note 33514 deleted from function.mktime by vincent
| From: | vincent@php.net | Date: | Mon, 18 Aug 2003 09:52:59 +0000 |
| Subject: | note 33514 deleted from function.mktime by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54570@lists.php.net to get a copy of this message | ||
Note Submitter: marc@grue.info
----
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).