note 33514 modified in function.mktime by stone
| From: | stone@php.net | Date: | Sat, 28 Jun 2003 20:59:17 +0000 |
| Subject: | note 33514 modified in function.mktime by stone | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51140@lists.php.net to get a copy of this message | ||
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).
--was--
[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).
http://www.php.net/manual/en/function.mktime.php