note 68557 added to function.date

From: Date: Tue, 01 Aug 2006 20:11:55 +0000
Subject: note 68557 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-115426@lists.php.net to get a copy of this message
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)) ---- Server IP: 216.235.15.211 Probable Submitter: 70.26.188.165 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/68557 Del: integrated -- https://master.php.net/note/delete/68557/integrated Del: useless -- https://master.php.net/note/delete/68557/useless Del: bad code -- https://master.php.net/note/delete/68557/bad+code Del: spam -- https://master.php.net/note/delete/68557/spam Del: non-english -- https://master.php.net/note/delete/68557/non-english Del: in docs -- https://master.php.net/note/delete/68557/in+docs Del: other reasons-- https://master.php.net/note/delete/68557 Reject -- https://master.php.net/note/reject/68557 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115426) next »