Text Size
Sunday, May 20, 2012
Get a look down
JavaScript >> Displaying items by tag: calculate last day
Displaying items by tag: calculate last day
Tuesday, 05 July 2011 09:49

Get the latest day of a month with PHP

Here's how you can get the latest day for a given month:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
date('t');
// result : the lastest day of the current day
 
$ts = time();
date('t', $ts);
// result : the same result
// PS : $ts is a unix timestamp so you can put any timestamp,
// it will give you the latest day for the month of this timestamp
 
date('Y-m-t');
// result : full date of the last day of the current month. Eg. 2011-07-31
 
date('t',strtotime('last month'));
// You can use strtotime also with a valid date string
Published in Code snippets
Usefull tricks