note 105344 added to function.strtotime
| From: | (MickoZ) | Date: | Wed, 10 Aug 2011 17:54:31 +0000 |
| Subject: | note 105344 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182403@lists.php.net to get a copy of this message | ||
This comment apply to PHP5+
We can now do thing like this with strtotime:
<?php
$weekMondayTime = strtotime('Monday this week');
?>
However this works based on a week starting Sunday. I do not know if we can tweak this PHP
behavior, anyone know?
If you want the timestamp of the start of the ISO Week (i.e. on Monday) as defined by ISO 8601, you
can use this one liner:
<?php
$isoWeekStartTime = strtotime(date('o-\\WW')); // {isoYear}-W{isoWeekNumber}
?>
You can also find out the start of week of any time and format it into an ISO date with another one
liner like this:
<?php
$isoWeekStartDate = date('Y-m-d', strtotime(date('o-\\WW', $time)));
?>
For more information about ISO-8601 and ISO week date:
http://en.wikipedia.org/wiki/ISO_8601#Week_dates
http://en.wikipedia.org/wiki/ISO_week_date
----
Server IP: 69.147.83.197
Probable Submitter: 69.165.152.129
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/105344
Del: integrated -- https://master.php.net/note/delete/105344/integrated
Del: useless -- https://master.php.net/note/delete/105344/useless
Del: bad code -- https://master.php.net/note/delete/105344/bad+code
Del: spam -- https://master.php.net/note/delete/105344/spam
Del: non-english -- https://master.php.net/note/delete/105344/non-english
Del: in docs -- https://master.php.net/note/delete/105344/in+docs
Del: other reasons-- https://master.php.net/note/delete/105344
Reject -- https://master.php.net/note/reject/105344
Search -- https://master.php.net/manage/user-notes.php