note 30334 deleted from function.strftime by derick
| From: | derick@php.net | Date: | Sat, 04 Nov 2006 10:44:24 +0000 |
| Subject: | note 30334 deleted from function.strftime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119385@lists.php.net to get a copy of this message | ||
Note Submitter: shaun at nospam dot phplabs dot com
----
I recently needed a way to find the first second of the current week. The catch was that
strftime("%u") considers Monday as the first day of the week, whereas I needed things
based on Sundays.
My solution was to determine how many days had elapsed since the previous Sunday (0 if today is a
Sunday), and subtract that may days from the current day's midnight timestamp:
$weekstart = mktime(0, 0, 0, date("m"), date("d"), date("Y")) -
((strftime("%u") == 7) ? 0 : (86400 * strftime("%u")));
This will assign the epoch stamp of the most recent Sunday at 00:00 (today at 00:00, if today is a
Sunday) to $weekstart.