note 110068 added to function.date-diff

From: Date: Sun, 16 Sep 2012 03:16:07 +0000
Subject: note 110068 added to function.date-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-190803@lists.php.net to get a copy of this message
I found this simple method works best... // The Start and End Dates $FirstDate = "01-01-2012" // Use "NOW" for today $SecondDate = "01-01-2012" // Use "NOW" for today // The Code to get the true age in days... // Replace "NOW" with the date if stated... if ($FirstDate=="NOW") { $FirstDate=date('d-m-Y') } if ($SecondDate=="NOW") { $SecondDate=date('d-m-Y') } //Get the Time between the two dates provided... $ta = strtotime(FirstDate)/60/60/24; $tb = strtotime(SecondDate)/60/60/24; //Calculate the Difference between the two times... $age = $ta-$tb; //output to screen echo $age." Day"; //adds a s to day to make days if output is 2 or more if($age>=2){ echo "s"; } //adds a s to day to make days if output is -2 or less if($age<=-2){ echo "s"; } //$age is the number of days between the FirstDate and SecondDate Example 1... $FirstDate = "01-01-2012" $SecondDate = "03-01-2012" Output = 2 Days Example 2... $FirstDate = "03-01-2012" $SecondDate = "01-01-2012" Output = -2 Days *** I hope this helps people that like me needed a negative output as well as positive *** ---- Server IP: 69.147.83.199 Probable Submitter: 77.98.249.52 ---- Manual Page -- http://www.php.net/manual/en/function.date-diff.php Edit -- https://master.php.net/note/edit/110068 Del: integrated -- https://master.php.net/note/delete/110068/integrated Del: useless -- https://master.php.net/note/delete/110068/useless Del: bad code -- https://master.php.net/note/delete/110068/bad+code Del: spam -- https://master.php.net/note/delete/110068/spam Del: non-english -- https://master.php.net/note/delete/110068/non-english Del: in docs -- https://master.php.net/note/delete/110068/in+docs Del: other reasons-- https://master.php.net/note/delete/110068 Reject -- https://master.php.net/note/reject/110068 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190803) next »