Summary of Time Calculation

Source: Internet
Author: User
Tags echo date

Calculating the time difference in php is sometimes troublesome!

However, I believe that any language, as long as it holds the rule rate, will be able to find a way, it is absolutely magical.

Date calculation is often performed in the work. The following is a summary of the experience gained from the work. Remember it first so that you will not forget it later!

1. The first calculation time period difference (which can be minute, second, or day)

$ Endtime = "18:10:00 ";
$ D1 = substr ($ endtime, 17,2); // second
$ D2 = substr ($ endtime, 14,2); // minute
$ D3 = substr ($ endtime, 11, 2); // hour
$ D4 = substr ($ endtime, 8, 2); // day
$ D5 = substr ($ endtime, 5, 2); // month
$ D6 = substr ($ endtime, 0, 4); // year

Echo $ d1. '-'. $ d2. '-'. $ d3. '-'. $ d5. '-'. $ d4. '-'. $ d6. "n ";

Echo date ("Y-m-d H: I: s"). "n ";
$ Now_T = mktime (date ("H"), date ("I"), date ("s"), date ("m"), date ("d "), date ("Y "));
Echo $ now_T. "n ";
$ Now_S = mktime ("$ d3", "$ d2", "$ d1", "$ d5", "$ d4", "$ d6 ");
Echo $ now_S. "n ";
$ End_TS = ($ now_S-$ now_T)/60; // calculate the remaining minutes
Echo $ end_TS;
?>

Note $ startdate = mktime ("0", "0", "0", "1", "1", "2000 ");
// The obtained value is the total number of seconds from January 1, 3600 to the parameter time. You can convert it to minute/60, 3600/24 days, or!

If the parameter in mktime () defaults, the current date is used.

2. It would be easy to have a database! If it is MSSQL, you can use a trigger! Use the datediff () function that specifically calculates the date difference!
If MYSQL is used, the calculation result calculated using the difference value of two date fields is saved in another numeric field! It can be called in time!

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.