[PHP] about the time calculation of the knot total

Source: Internet
Author: User
Tags date echo date end
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!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.