Re: Getting the date of Monday from a week number and year

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux