note 30334 added to function.strftime
| From: | shaun at nospam dot phplabs dot com | Date: | Fri, 14 Mar 2003 10:03:47 +0000 |
| Subject: | note 30334 added to function.strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45294@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.strftime.php
http://master.php.net/manage/user-notes.php?action=edit+30334
http://master.php.net/manage/user-notes.php?action=delete+30334
http://master.php.net/manage/user-notes.php?action=reject+30334