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
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:
In PHP 5.4+ you can do this:
If you prefer a concise way to do this, and already have the year and month in numerical values, you can use
date()
:In php 5.2 you can use:
This is everything you need: