views:

99

answers:

3

Hallo all.

if i have week number 42 and i need to know what dates there are in this week, can sombardy maby tell me a easy way to get this info?

tanks a lot :)

+1  A: 

There is a thread discussing how to get the first date of the week (Monday) using the week of the year and the year. That should help you.

Matthew Jones
+2  A: 
<?php
$date = new DateTime('2009W52');
echo $date->format(DateTime::RFC850);

Which outputs

Monday, 21-Dec-09 00:00:00 EET

and you can modify it like

$date->modify("last monday");
$date->modify("next monday");

Week has to be zero padded for weeks 1-9

raspi
A: 

I know you have already accepted an answer, but I feel this bit of code is also useful.

$year = date("Y");
$week = date("W"); // Can be replaced with '42' for your example.
$start = strtotime($year.'W'.$week.'1');

This will return a unix timestamp which some people find easier to manipulate.

You can also use this for PHP 5.1 and higher.

$start = date(datetime::ISO8601, strtotime("2009W421"));

Using the above method you can easily format it.

Hope this provides useful to someone.

-Mathew

The Pixel Developer
date() has limitations like can't go above 1970-01-01. Built-in DateTime class fixes majority of these kind of problems.
raspi
Do you mean below 1970? Thank you for the comment, I learned something new today.
The Pixel Developer
Yeah, i meant below :)
raspi