note 100471 added to datetime.diff

From: Date: Mon, 18 Oct 2010 13:32:24 +0000
Subject: note 100471 added to datetime.diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-173242@lists.php.net to get a copy of this message
A modification of Dennis C's post on May 10th, 2010. This allows you to set the interval you're looking for as well as returns a positive or negative according to whether the 2nd date is greater than the first. /** * modified from http://www.php.net/manual/en/datetime.diff.php#97810 * @param DateTime $oDate1 * @param DateTime $oDate2 * @param string $sInterval (second, minute, hour, day, week, month, year) * @return int */ function date_diff_interval(DateTime $oDate1, DateTime $oDate2, $sInterval) { $iCount = 0; switch (true) { case $oDate1 < $oDate2: while($oDate1 < $oDate2){ $oDate1->modify('+1 ' . $sInterval); $iCount++; } break; case $oDate1 > $oDate2: while($oDate1 > $oDate2){ $oDate1->modify('-1 ' . $sInterval); $iCount--; } break; } return $iCount; } ---- Server IP: 69.147.83.197 Probable Submitter: 74.72.194.109 ---- Manual Page -- http://www.php.net/manual/en/datetime.diff.php Edit -- https://master.php.net/note/edit/100471 Del: integrated -- https://master.php.net/note/delete/100471/integrated Del: useless -- https://master.php.net/note/delete/100471/useless Del: bad code -- https://master.php.net/note/delete/100471/bad+code Del: spam -- https://master.php.net/note/delete/100471/spam Del: non-english -- https://master.php.net/note/delete/100471/non-english Del: in docs -- https://master.php.net/note/delete/100471/in+docs Del: other reasons-- https://master.php.net/note/delete/100471 Reject -- https://master.php.net/note/reject/100471 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173242) next »