note 51402 added to function.strtotime

From: Date: Tue, 29 Mar 2005 22:16:02 +0000
Subject: note 51402 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-87163@lists.php.net to get a copy of this message
Just pointing out that date( 'M', strtotime( 'last month', [some timestamp]) ) will not actually give the name of the previous month if the day of [some timestamp] doesn't exsist in the previous month. It will instead round up, and give the name of one month AFTER the previous month ('this month', that is). For example date( 'M', strtotime( 'last month', [March 31st]) ) will return 'Mar'. This is documented here: http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html (also linked from this manual page), but is not easy to find: " The fuzz in units can cause problems with relative items. For example, `2003-07-31 -1 month' might evaluate to 2003-07-01, because 2003-06-31 is an invalid date. To determine the previous month more reliably, you can ask for the month before the 15th of the current month. For example: $ date -R Thu, 31 Jul 2003 13:02:39 -0700 $ date --date='-1 month' +'Last month was %B?' Last month was July? $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!' Last month was June! " Hope that helps somebody! ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51402 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51402&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51402&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51402&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51402&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51402&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51402&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87163) next »