Marko Marko - 3 months ago 10
PHP Question

DateTime modify string for first day of current year

im looking for the DateTime modify String for the first day of the year (now 1. January 2011). I tried the following:

<?php

$time = new DateTime();

// works as expected, the first day of the current month
$time->modify('first day of this month');
echo $time->format('c')."\n";


// this doesn't work. I also tried several other ways
$time->modify('first day of january');
echo $time->format('c')."\n";

>


I know there are other ways to retrieve the date, but I search an string for DateTime->modify() no other solution.

Answer

You should specify the year too, as you can see in this example:

"first day of January 2008"

from the official doc.

Update: It works on php version >= 5.3.6