note 33514 added to function.mktime
| From: | marc at grue dot info | Date: | Sat, 28 Jun 2003 11:09:41 +0000 |
| Subject: | note 33514 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51132@lists.php.net to get a copy of this message | ||
[TO EDITOR: IF POSSIBLE REMOVE OLD NOTE AND THIS COMMENT - Sorry, found a bug in my script, posted
27-Jun-2003 - This one works: ]
To calculate the date of the first day in a week from a given $year and $week_number (ex week 2 of
2003):
function week_date_unix ($year, $week_number) {
// Numeric day of the week for the 1st of January, $year
$no = date("w", mktime(0,0,0,1,1,$year));
// First day of first week in $year
$first_day = mktime(0,0,0,1,1,$year) - ($no-1) * 86400;
// Add $week weeks to first day (current week is not to be added)
$add_no_of_weeks = $week_number-1;
return strtotime("$add_no_of_weeks weeks", $first_day);
}
Returns the monday in that week as a UNIX timestamp (ex 1041807600 = 6th of January 2003).
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33514
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33514&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33514&report=yes