note 87975 modified in function.date by felipe
| From: | felipe@php.net | Date: | Sat, 17 Jan 2009 01:29:46 +0000 |
| Subject: | note 87975 modified in function.date by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149359@lists.php.net to get a copy of this message | ||
This is adapted from sourabhshankar AT gmail DOT com
to allow you to get the week beginning and end from any day you give it.
<?php
$user_date = '2008-12-31';
$sun = 0; //sunday = start of week
$sat = 6; //saturday = end of week
$user_date = strtotime($user_date);
$dayOfWeek = date('w', $user_date); // get day number
$days_until_sat = $sat - $dayOfWeek;
$days_from_sun = $dayOfWeek - $sun;
$week_start = strtotime(" - $days_from_sun days", $user_date);
$week_end = strtotime(" + $days_until_sat days", $user_date);
?>
--was--
This is adapted from sourabhshankar AT gmail DOT com
to allow you to get the week beginning and end from any day you give it.
$user_date = '2008-12-31';
$sun = 0; //sunday = start of week
$sat = 6; //saturday = end of week
$user_date = strtotime($user_date);
$dayOfWeek = date('w', $user_date); // get day number
$days_until_sat = $sat - $dayOfWeek;
$days_from_sun = $dayOfWeek - $sun;
$week_start = strtotime(" - $days_from_sun days", $user_date);
$week_end = strtotime(" + $days_until_sat days", $user_date);
http://php.net/manual/en/function.date.php