note 68557 deleted from function.date by bjori
| From: | bjori@php.net | Date: | Wed, 02 Aug 2006 13:08:26 +0000 |
| Subject: | note 68557 deleted from function.date by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115476@lists.php.net to get a copy of this message | ||
Note Submitter: cjmarks at gmail dot com
Reason: in docs
----
I'm coding up a quick PHP scheduling calendar based off weeks beginning on Sunday, and I
discovered I needed a way to get at the Sunday before week n. The previous script to find out the
Monday that begins the week relies on loops, and to me that represents unnecessary processor time.
I've written a quick non-looping script to identify the Sunday:
<?php
function fetchSunday($week, $year) {
// Find an arbitrary day within the week
$inittime = mktime(0,0,0,1,7*$week,$year);
// Adjust back to Sunday
$sunday = $inittime - (60*60*24*date('w', $inittime));
// Return the timestamp for the Sunday
return $sunday;
}
?>
Of course, if you want the Monday you change the adjustment formula to
(60*60*24*(date('w', $inittime)-1))