Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PHP, is there an easy way to get the first and last date of a month?

Tags:

php

I need to get the first and last day of a month in the format YYYY-MM-DD given only the month and year. Is there a good, easy way to do this?

like image 251
Thomas Owens Avatar asked Sep 04 '08 12:09

Thomas Owens


People also ask

How can I get start date and end date in php?

php function days($date1, $date2) { $date1 = strtotime($date1); $date2 = strtotime($date2); return ($date2 - $date1) / (24 * 60 * 60); } $date1 = '20100820'; $date2 = '20100930'; echo days($date1, $date2); ?>

How can I get the last date of last month in php?

Get Last Day Of The Previous Month:$lastDay = date('t',strtotime('last month')); print_r($lastDay);

How can I get 30 Day date in php?

php $next_due_date = date('y-m-d',strtotime('+30 days',strtotime('echo $userRow3["due_date"]'))) .

How can I get last week start and end date in php?

date("m/d/Y", strtotime("last week monday")); date("m/d/Y", strtotime("last week sunday")); It will give the date of Last week's Monday and Sunday.


1 Answers

$first = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year)); $last = date('Y-m-t', mktime(0, 0, 0, $month, 1, $year)); 

See date() in PHP documentation.

like image 136
Michał Niedźwiedzki Avatar answered Sep 26 '22 13:09

Michał Niedźwiedzki