note 53428 added to function.date

From: Date: Wed, 01 Jun 2005 11:14:40 +0000
Subject: note 53428 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-89733@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53428 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53428&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53428&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53428&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53428&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53428&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53428&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89733) next »