Getting the first day of the month of a specific month / year

Is there a better way to return the date on the first day of a particular month / year than the following?

$month = date('m');
$year = date('Y');
$from = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
+5
source share
4 answers

This seems like the right way to do this with me. You might want to make it a function.

-1
source

It's not quite elegant, but I like it because it is so readable:

strtotime("first day of this month");
+11
source

?

date("Y-m-01")

;)

( , , , strtotime, , !)

+8

date("Y-m-01") ; , . :

if(!isset($FromDate))
          $FromDate=date('Y-m-01'); //date with current month first day

if(!isset($ToDate))
         $ToDate=date('Y-m-d'); /////current date

, .

+2

All Articles