Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get last day of the month using php [duplicate]

Tags:

php

How to get last day of the month using php ?

<?php
     echo date('?-?-?');
?>
like image 910
jems peterson Avatar asked May 03 '13 04:05

jems peterson


3 Answers

try this

$day=date('Y-m-t'); // gives last day of current month

OR

$d = new DateTime( '2013-05-03' ); 
echo $d->format( 'Y-m-t' );
like image 107
Yogesh Suthar Avatar answered Oct 13 '22 22:10

Yogesh Suthar


<?php
$day=new DateTime('last day of this month'); 
echo $day->format('M jS');
?>
like image 10
Mayur Patel Avatar answered Oct 31 '22 00:10

Mayur Patel


The date function documentation says that t represents number of days in current month:

$day = date( 't-m-Y' );
like image 9
hjpotter92 Avatar answered Oct 31 '22 01:10

hjpotter92