note 106363 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Mon, 31 Oct 2011 15:13:13 +0000 |
| Subject: | note 106363 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184256@lists.php.net to get a copy of this message | ||
How to get the week starting date by giving a week number and the year. Monday first day in week
<?php
function WeekStartDate($week,$year,$format="d-m-Y") {
date_default_timezone_set('Europe/Paris');
$firstDayInYear=date("N",mktime(0,0,0,1,1,$year));
if ($firstDayInYear<5)
$shift=-($firstDayInYear-1)*86400;
else
$shift=(8-$firstDayInYear)*86400;
if ($week>1) $weekInSeconds=($week-1)*604800; else $weekInSeconds=0;
$timestamp=mktime(0,0,0,1,1,$year)+$weekInSeconds+$shift;
return date($format,$timestamp);
}
echo WeekStartDate(44,2011);
//result: 31-10-2011
?>
--was--
How to get the week starting date by giving a week number and the year. Monday first day in week
function WeekStartDate($week,$year,$format="d-m-Y") {
date_default_timezone_set('Europe/Paris');
$firstDayInYear=date("N",mktime(0,0,0,1,1,$year));
if ($firstDayInYear<5)
$shift=-($firstDayInYear-1)*86400;
else
$shift=(8-$firstDayInYear)*86400;
if ($week>1) $weekInSeconds=($week-1)*604800; else $weekInSeconds=0;
$timestamp=mktime(0,0,0,1,1,$year)+$weekInSeconds+$shift;
return date($format,$timestamp);
}
echo WeekStartDate(44,2011);
//result: 31-10-2011
http://php.net/manual/en/function.date.php