note 87975 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 22 Mar 2009 18:45:03 +0000 |
| Subject: | note 87975 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152296@lists.php.net to get a copy of this message | ||
Note Submitter: kavika7 at hotmail dot com
----
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);
?>