Last active
August 9, 2020 19:08
-
-
Save IronGhost63/d8b9b25052bda3ee77773bcb201eed7b to your computer and use it in GitHub Desktop.
Find first and last date of given week
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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