Kythin's Rants Kythin rants about all kinds of things, but mainly website development, SEO and PC Gaming.

19May/110

Get the first and last days of last month in PHP

Here's a really simple way to get the first and last dates of last month in PHP using strtotime. This'll also format the dates correctly to use in comparisons with MySQL 'TIMESTAMP' fields! Nifty eh?


$lastmonth = strtotime("last month");
$fromdate = date('Ym01 00:00:00',$lastmonth);
$todate = date('Ymt 23:59:59',$lastmonth);

echo($fromdate.' to '.$todate);

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.