RE: How would i construct a date from year/week?

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

 



> How on earth would I do this? How can I 
> construct a date only given a year and a 
> week number?
> I hope you guys can help me here, as I 
> have absolutely NO idea :)

// whatever week number you are working with; arbitrary value here
$weekNumber = 37; 

// seconds * minutes * hours;
$day = 60 * 60 * 24; 

// days in a week
$week = 7; 

// get the unix time for Jan 1 of this year
$firstDayOfThisYear = mktime( 0, 0, 0, 1, 1, date( 'Y' ));

// calculate the unix time for the date of the week number
$weekNumberDate = $firstDayOfYear + ( $weekNumber * day * week );

// This will put you X weeks out of the day that Jan 1 fell on.
// If Jan 1 was on a Thursday, this date should also be on a Thursday.
// Using date( 'N', $weekNumberDate ), you can find out how many days
// you need to subtract to get your Monday date
echo date( 'm/d/Y', $weekNumberDate );

thnx,
Chris

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