Several ways to calculate the time difference in PHP, the calculation of the time difference in PHP is sometimes a hassle! But as long as you have the use of the date function, that's a simple thing to do:
A simple example is calculating the number of days to borrow, which requires PHP to calculate on a daily basis, and here's a few ways to implement this date calculation:
(1) If there is a database is very easy! If MSSQL can use triggers! A function that calculates the date difference specifically DATEDIFF ()!
In the case of MySQL, use the two-date field's difference calculation to save the result in another numeric field! Time to call!
(2) If there is no database, then you have to completely use the PHP time and date function! The following main description:
Example: Calculates 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;
If the parameter in Mktime () defaults, that means the current date is used, so that you can calculate the number of days from the date the book was borrowed.