How to get first day of current month in php?

Php

Php Problem Overview


What I want to do is get 1st date of current month

Here is how to get last day of the current month

date('d-m-Y', strtotime('last day of this month'))

I've tried to use this, but it didn't work for me

date('d-m-Y', strtotime('first day of this month'))    

Any idea how to solve my problem ?

Php Solutions


Solution 1 - Php

date('01-m-Y') should do it ;)

Solution 2 - Php

date('d-m-Y', strtotime(date('Y-m-1')));

Solution 3 - Php

$firstDayUTS = mktime (0, 0, 0, date("m"), 1, date("Y"));
$lastDayUTS = mktime (0, 0, 0, date("m"), date('t'), date("Y"));

$firstDay = date("d-m-Y", $firstDayUTS);
$lastDay = date("d-m-Y", $lastDayUTS);

Solution 4 - Php

How about :

date('1-m-Y',strtotime('this month'));

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOscarView Question on Stackoverflow
Solution 1 - PhpNiet the Dark AbsolView Answer on Stackoverflow
Solution 2 - PhpzerkmsView Answer on Stackoverflow
Solution 3 - PhpAndrey ZarovnyaevView Answer on Stackoverflow
Solution 4 - PhpRaptorView Answer on Stackoverflow