Re: Getting the date of Monday from a week number and year
| From: | Tom Rogers | Date: | Wed, 03 Nov 2004 13:32:39 +0000 |
| Subject: | Re: Getting the date of Monday from a week number and year | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201031@lists.php.net to get a copy of this message | ||
Hi,
Wednesday, November 3, 2004, 8:29:27 PM, you wrote:
S> Hi,
S> is it possible to get php to calculate the date of the monday given a week
S> number and the year? I have looked http://uk.php.net/strtotime
S> here and can
S> find refererence to everything but this!
S> Thanks for your help,
This may do what you want:
function getMonday($date){
$rdate = getdate(strtotime($date.' 00:00:00'));
$monday = $rdate[0]; // assume it is monday
if($rdate['wday'] > 1)$monday = $rdate[0] -
(($rdate['wday']-1)*(60*60*24));
elseif($rdate['wday'] < 1) $monday = $rdate[0] -(6* (60*60*24));
$date = date('Y-m-d',$monday);
return $date;
}
$year = 2004;
$weeks = 2; //second week
$monday = getMonday($year.'-01-01');
$wanted_monday = date('Y-m-d',strtotime('+ '.($weeks-1).'
weeks',strtotime($monday)));
echo "Week $weeks Monday was $wanted_monday <br>";
--
regards,
Tom