note 35160 added to function.strtotime
| From: | shadowfaxx at CC dot com | Date: | Thu, 21 Aug 2003 16:25:51 +0000 |
| Subject: | note 35160 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54827@lists.php.net to get a copy of this message | ||
In the note below by "php_net at evgeny dot ee", the get_monday() function could be
simplified by using :
strtotime(" monday", $first_date);
or
strtotime(" first monday", $first_date);
instead of:
strtotime(" next monday", $first_date) - 604800;
As per the GNU date input format (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html),
"next" will give you the 2nd occurance from the specified date, in which case you have to
subtract 604800 (1 week in seconds) to return to the 1st occurance. Instead of going one week past
the required date then coming back to it, just use "first" or the day name itself (in this
case 'monday') to arrive at the 1st occurance.
function get_monday($week, $year=""){
$first_date = strtotime("1 january ".($year ? $year : date("Y")));
if(date("D", $first_date)=="Mon") {
$monday = $first_date;
} else {
$monday = strtotime("first monday", $first_date);
}
$plus_week = "+".($week-1)." week";
return strtotime($plus_week, $monday);
}
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35160
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35160&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35160&report=yes