RE: [PHP] How would i construct a date from year/week?
| From: | Chris Boget | Date: | Sun, 08 Jul 2007 12:21:18 +0000 |
| Subject: | RE: [PHP] How would i construct a date from year/week? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258469@lists.php.net to get a copy of this message | ||
> 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