Amadeus45 Amadeus45 - 1 month ago 5
PHP Question

How to get the first day of a given week number in PHP (multi-platform)?

What is the simplest way to do it in PHP ?

I want the date of the Monday of a given week number of a year (example : week number 3 of 2009)

Thanks !

EDIT : If you use Linux only machines, use cletus' solution, however I am looking for something that can work on Windows AND Linux.

Answer

Yet another solution:

<?php
        $week = 3;
        $year = 2009;

        $timestamp = mktime( 0, 0, 0, 1, 1,  $year ) + ( $week * 7 * 24 * 60 * 60 );
        $timestamp_for_monday = $timestamp - 86400 * ( date( 'N', $timestamp ) - 1 );
        $date_for_monday = date( 'Y-m-d', $timestamp_for_monday );
?>
Comments