note 88776 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 22 Mar 2009 18:43:58 +0000 |
| Subject: | note 88776 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152290@lists.php.net to get a copy of this message | ||
Note Submitter: twdsje at gmail dot com
----
Another slight adaptation from the code posted earlier that you might find slightly more useful.
http://us2.php.net/manual/en/function.date.php#87975
Takes a unix timestamp and returns the beginning or end of that week as a unix timestamp. If no
timestamp is provided the current time is used.
<?php
function weekStart($time = null)
{
if($time == null)
$time = time();
$sun = 0; //sunday = start of week
$dayOfWeek = date('w', $time);
$days_from_sun = $dayOfWeek - $sun;
return $time - $days_from_sun * 24 * 60 * 60;
}
function weekEnd($time = null)
{
if($time == null)
$time = time();
$sat = 6; //saturday = end of week
$dayOfWeek = date('w', $time);
$days_until_sat = $sat - $dayOfWeek;
return $time + $days_until_sat * 24 * 60 * 60;
}
?>