note 84615 deleted from function.strtotime by derick

From: Date: Sun, 03 Aug 2008 11:51:01 +0000
Subject: note 84615 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143102@lists.php.net to get a copy of this message
Note Submitter: debbie dot smith at itontap dot com ---- the post with the date_addmonths function doesn't really work, and its returning a timestamp not a date. i find the following function works well for me, to address the same problem. <?php # this function is needed for 31-jan-08 + 1 month to give 28-feb-08, etc. if (!function_exists('time_addmonths')) { function time_addmonths($n_months, $timestamp=null) { if (is_null($timestamp)) $timestamp=time(); $newt = strtotime("+$n_months months",$timestamp); $newd = date('d',$newt); if (date('d',$timestamp) != $newd) { # its rolled over to the next month so subtract the extra days $newt = strtotime("-$newd days",$newt); } return $newt; } } ?>

« previous php.notes (#143102) next »