The code is as follows:
/*
* Calculate the month difference of two time periods.
* @ Param $ st start time $ et end time (timestamp format)
* @ Return $ difference value returned by total
*/
Function getMonthNum ($ st, $ et)
{
$ S_m = date ('N', $ st );
$ E_m = date ('N', $ et );
$ S_y = date ('Y', $ st );
$ E_y = date ('Y', $ et );
$ Total = 13-$ s_m + ($ e_y-$ s_y-1) * 12 + $ e_m; // calculates the month difference.
Return $ total;
}
Example 2
The code is as follows:
$ One = strtotime ('2017-05-08 07:02:40 '); // start time stamp
$ Tow = strtotime ('2017-12-25 00:00:00 '); // end time stamp
$ Cle = $ tow-$ one; // Get the timestamp difference
/* This is just a prompt
Echo ceil ($ cle/60); // The total number of minutes
Echo ceil ($ cle/3600); // calculates the total number of hours
Echo ceil ($ cle/3600/24); // returns the total number of days
*/
/* Ceil () function, which is an integer in the next method */
$ D = cell ($ cle/3600/24 );
$ H = cell ($ cle % (3600*24)/3600); // % obtain the remainder
$ M = cell ($ cle % (3600*24)/60 );
Echo "two time differences $ d days $ h hours $ m points"
?>
Example 3
The code is as follows:
/*
*
* (Www.111cn.net) function: calculate two dates in YYYY-MM-DD format, a few days different
*
*/
Function getChaBetweenTwoDate ($ date1, $ date2 ){
Example 4: One of my favorite computing tasks can be calculated as hours and seconds. of course, you still need to perform the calculation based on your needs.
From: http://www.111cn.net/phper/php-cy/66323.htm
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.