date - The first day of the current month in php using date_modify as DateTime object -
i can monday week with:
$monday = date_create()->modify('this monday');
i same ease 1st of month. how can achieve that?
thanks
requires php 5.3 work ("first day of" introduced in php 5.3). otherwise example above way it:
<?php // first day of month $d = new datetime('first day of month'); echo $d->format('js, f y'); // first day of specific month $d = new datetime('2010-01-19'); $d->modify('first day of month'); echo $d->format('js, f y'); // alternatively... echo date_create('2010-01-19') ->modify('first day of month') ->format('js, f y');
in php 5.4+ can this:
<?php // first day of month echo (new datetime('first day of month'))->format('js, f y'); echo (new datetime('2010-01-19')) ->modify('first day of month') ->format('js, f y');
if prefer concise way this, , have year , month in numerical values, can use date()
:
<?php echo date('y-m-01'); // first day of month echo date("$year-$month-01"); // first day of month chosen
Comments
Post a Comment