note 53428 deleted from function.date by aidan

From: Date: Sun, 31 Jul 2005 12:33:52 +0000
Subject: note 53428 deleted from function.date by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-92816@lists.php.net to get a copy of this message
Note Submitter: pmcdevitt(at)cesales.com ---- It is important to note in the mktime() example that $lastmonth doesn't always give you last months date. If you are on the 31st of a month and do: $lastmonth=mktime(0,0,0,date("m")-1,date("d"),date("Y")); the resulting day doesn't exist and rolls over to the next day. So if today is may 31st, $lastmonth will equal may 1st, because april 31st does not exist. For my purposes all I need is the month so I check to see if date("d") = 31. If it does then I use: $lastmonth=mktime(0,0,0,date("m")-1,date("d")-5,date("Y")); $lastmonth= date("M", $lastmonth); You could subtract just one, but Februarys and leap years mess it up. 5 is just arbitrary.

« previous php.notes (#92816) next »