Skip to content

Instantly share code, notes, and snippets.

@IronGhost63
Last active August 9, 2020 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronGhost63/d8b9b25052bda3ee77773bcb201eed7b to your computer and use it in GitHub Desktop.
Save IronGhost63/d8b9b25052bda3ee77773bcb201eed7b to your computer and use it in GitHub Desktop.
Find first and last date of given week
<?php
// Get timestamp
$date_string = 'June 19, 2020';
$timestamp = strtotime( $date_string );
// Get weekday for given date
// Return 0-6 for Sun to Sat
$weekday = date( 'w', $timestamp );
// Calculate first and last date of given week
// 86400 = seconds in a day
$first_day = date( 'D, F j, Y', $timestamp - ( $weekday * 86400 ) );
$last_day = date( 'D, F j, Y', $timestamp + ( ( 6 - $weekday ) * 86400 ) );
echo $first_day . "\n";
echo $last_day . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment