0

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

ParisNakitaKejser
  • 12,112
  • 9
  • 46
  • 66

3 Answers3

2
<?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
  • 5,962
  • 3
  • 34
  • 51
1

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
  • 25,644
  • 17
  • 102
  • 155
0

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
  • 13,282
  • 10
  • 43
  • 60