note 51402 deleted from function.strtotime by derick

From: Date: Sun, 15 Jul 2007 12:50:06 +0000
Subject: note 51402 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128589@lists.php.net to get a copy of this message
Note Submitter: dfuchs at donotspam dot gmail dot com ---- 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!

« previous php.notes (#128589) next »