note 95388 deleted from function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Thu, 31 Dec 2009 16:37:58 +0000 |
| Subject: | note 95388 deleted from function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-164499@lists.php.net to get a copy of this message | ||
Note Submitter: dtbaker at gmail
----
When trying to find X months ago do not use strtotime("-$x months"); this will fail on 31
day months.
eg: running date("n",strtotime("-1 months")); on 31st of Dec will return 12
(Dec), not 11 (Nov) as I previously expected.
Instead you can use something like this:
<?php
$months_ago = 1; // change this to whatever
$month = date("n") - ($months_ago % 12);
$year = date("Y") - ($months_ago % 12);
?>
<?php
$months_ago = 15; // change this to whatever
$month = date("n") - ($months_ago % 12);
$year = date("Y") - ($months_ago % 12);
?>