Last active
November 1, 2015 19:25
-
-
Save jblyberg/97845a429c81b967f222 to your computer and use it in GitHub Desktop.
Working with Dates for Weekly Calendar
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
$year = date('Y'); | |
$week_no = date('W'); | |
$week_start = new DateTime(); | |
$week_start->setISODate($year, $week_no); | |
echo $week_start->format('l jS F (Y-m-d)'); // Monday for the current week | |
// Gets the week range for given date YYYY-MM-DD | |
function rangeWeek($datestr) { | |
date_default_timezone_set(date_default_timezone_get()); | |
$dt = strtotime($datestr); | |
$res['start'] = date('N', $dt) == 1 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('last monday', $dt)); | |
$res['end'] = date('N', $dt) == 7 ? date('Y-m-d', $dt) : date('Y-m-d', strtotime('next sunday', $dt)); | |
return $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment