note 120309 added to function.strtotime

From: Date: Fri, 09 Dec 2016 21:09:34 +0000
Subject: note 120309 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-208299@lists.php.net to get a copy of this message
addMonth solusion $date = addMonth("2015-01-31", 1); // return 2015-02-28 $date = addMonth("2015-01-31", 3); // return 2015-04-30 $date = addMonth("2015-02-28", 1); // return 2015-03-28 (of corst :) ) function addMonth($date, $countOfMonth) { $day = date("d", $date); $month = date("m", $date); $year = date("Y", $date); $dateOut = mktime(0, 0, 0, $month + $countOfMonth, $day, $year); $monthOut = date("m", $dateOut); $yearOut = date("Y", $dateOut); if(($month + $countOfMonth) % 12 != $monthOut) { if($year != $yearOut) { $m = $month + $countOfMonth; $m = $m % 12; $lastDayOfMonth = cal_days_in_month(CAL_GREGORIAN, $m, $yearOut); $dateOut = mktime(0, 0, 0, $m, $lastDayOfMonth, $yearOut); } else { $lastDayOfMonth = cal_days_in_month(CAL_GREGORIAN, $month + $countOfMonth, $year); $dateOut = mktime(0, 0, 0, $month + $countOfMonth, $lastDayOfMonth, $year); } } return date("Y-m-d", $dateOut); } ---- Server IP: 72.52.91.14 Probable Submitter: 31.11.160.2 ---- Manual Page -- http://php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/120309 Del: integrated -- https://master.php.net/note/delete/120309/integrated Del: useless -- https://master.php.net/note/delete/120309/useless Del: bad code -- https://master.php.net/note/delete/120309/bad+code Del: spam -- https://master.php.net/note/delete/120309/spam Del: non-english -- https://master.php.net/note/delete/120309/non-english Del: in docs -- https://master.php.net/note/delete/120309/in+docs Del: other reasons-- https://master.php.net/note/delete/120309 Reject -- https://master.php.net/note/reject/120309 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#208299) next »