Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top