How to calculate the time difference in PHP
There are several ways to calculate the time difference in PHP, and it is sometimes a hassle to calculate the difference in PHP! But as long as you have the use of the date-times function, these things become simpler:
A simple example is calculating the number of days to borrow, which requires PHP to calculate on a daily basis, and here are a few ways to implement this date calculation:
(1) It's easy if you have a database! If MSSQL can use a trigger! Use a function DateDiff () that calculates the date difference.
If MySQL is the result of the calculation of the difference between the two date fields, the results are saved in another numeric field! Time to call!
(2) If you don't have a database, you have to use PHP's time-date function completely! The following are the main explanations:
Example: Calculate the number of days from May 3, 1998 to 1999-6-5:
$enddate =mktime ("0", "0", "0", "6", "5", "1999");
The resulting value is the total number of seconds from 1970-1-1 to the parameter time: is an integer. So
The following code is so much more:
$days =round (($enddate-$startdate)/3600/24);
Echo $days;
Days for the day to get;
If the parameter in Mktime () is the default, it means that the current date is used, so that the number of days from the borrowing date is calculated.
http://www.bkjia.com/PHPjc/847197.html www.bkjia.com true http://www.bkjia.com/PHPjc/847197.html techarticle how to calculate the time difference in PHP several methods of calculating the time difference in PHP, the calculation of the time difference in PHP is sometimes a hassle! But as long as you've mastered the use of datetime functions, these ...