note 84615 added to function.strtotime

From: Date: Tue, 22 Jul 2008 03:10:18 +0000
Subject: note 84615 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-142482@lists.php.net to get a copy of this message
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. # 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; } } ---- Server IP: 117.104.160.194 Probable Submitter: 61.68.30.75 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/84615 Del: integrated -- https://master.php.net/note/delete/84615/integrated Del: useless -- https://master.php.net/note/delete/84615/useless Del: bad code -- https://master.php.net/note/delete/84615/bad+code Del: spam -- https://master.php.net/note/delete/84615/spam Del: non-english -- https://master.php.net/note/delete/84615/non-english Del: in docs -- https://master.php.net/note/delete/84615/in+docs Del: other reasons-- https://master.php.net/note/delete/84615 Reject -- https://master.php.net/note/reject/84615 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#142482) next »