I can get Monday this week with:
$monday = date_create()->modify('this Monday');
I would like to get with the same ease the 1st of this month. How can I achieve that?
Thanks
I can get Monday this week with:
$monday = date_create()->modify('this Monday');
I would like to get with the same ease the 1st of this month. How can I achieve that?
Thanks
Ugly, (and doesn't use your method call above) but works:
echo 'First day of the month: ' . date('m/d/y h:i a',(strtotime('this month',strtotime(date('m/01/y')))));
Requires PHP 5.3 to work ("first day of" is introduced in PHP 5.3). Otherwise the example above is the only way to do it:
<?php
$d = new DateTime('2010-01-19');
$d->modify('first day of this month');
echo $d->format('jS, F Y');
?>
You can do it like this:
$firstday = date_create()->modify('first day January 2010');
In php 5.2 you can use:
<? $d = date_create();
print date_create($d->format('Y-m-1'))->format('Y-m-d') ?>