Calculating the time difference in PHP is sometimes a hassle!
However, I believe that any language, as long as the grip of the regulation rate can find a way, is absolutely rotten to the magic.
Work often to carry out the date calculation, the following summary of several work summed up the experience. Make a note lest you forget it later!
1. First calculation time period difference (can be minutes, seconds, days)
$endtime = "2004-09-09 18:10:00";
$d 1=substr ($endtime, 17,2); Seconds
$d 2=substr ($endtime, 14,2); Part
$d 3=substr ($endtime, 11,2); When
$d 4=substr ($endtime, 8,2); Day
$d 5=substr ($endtime, 5,2); Month
$d 6=substr ($endtime, 0,4); Years
echo $d 1. '. $d 2 '-'. $d 3. '-'. $d 5. '-'. $d 4. '-'. $d 6. ' n ";
echo Date ("Y-m-d h:i:s"). " n ";
$now _t=mktime ("H"), Date ("I"), date ("s"), date ("M"), Date ("D"), Date ("Y"));
echo $now _t. " n ";
$now _s=mktime ("$d 3", "$d 2", "$d 1", "$d 5", "$d 4", "$d 6");
echo $now _s. " n ";
$end _ts= ($now _s-$now _t)/60; Calculate remaining minutes
echo $end _ts;
?>
Note $startdate =mktime ("0", "0", "0", "1", "1", "2000");
The resulting value is the total number of seconds from 1970-1-1 to the parameter time so as to divide/60 o'clock/3,600 days/3600/24!
If the parameter in Mktime () defaults, that means the current date is used.
2. If you have a database, it's easy! If MSSQL can use triggers! A function that calculates the date difference specifically DATEDIFF () can!
In the case of MySQL, use the two-date field's difference calculation to save the result in another numeric field! Time to call!