PHP calculates the difference of two times (seconds per day, month)

Source: Internet
Author: User

Instance code for month difference between two times:

 The code is as follows \$yourdate = "2012-10-20";\$yourdate _unix=strtotime (\$yourdate);Echo (Date ("Y", \$yourdate _unix)-date ("Y")) *12+ (date ("M", \$yourdate _unix)-date ("M"));

Example 1

 The code is as follows /** Calculates month difference for 2 time periods* @param \$st start time \$et end time (timestamp format)* @return The difference \$total return*/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) * + \$e _m; Calculate Month Differencereturn \$total;}

Example 2

 The code is as follows

Example 3

 The code is as follows ? Php/*** Function function: Calculate two date in YYYY-MM-DD format, the difference is a few days**/function Getchabetweentwodate (\$date 1, \$date 2) {\$Date _list_a1=explode ("-", \$date 1);\$Date _list_a2=explode ("-", \$date 2);\$d 1=mktime (0,0,0, \$Date _list_a1, \$Date _list_a1, \$Date _list_a1);\$d 2=mktime (0,0,0, \$Date _list_a2, \$Date _list_a2, \$Date _list_a2);\$Days =round ((\$d 1-\$d 2)/3600/24);return \$Days;}echo getchabetweentwodate (' 2010-08-11 ', ' 2010-08-16 ');echo "
";echo getchabetweentwodate (' 2010-08-16 ', ' 2010-08-11 ');?>

Example 4

 The code is as follows ";echo \$hour. " Hours
";echo \$minute. " Minutes
";echo \$second. " SEC
";?>

Example four is my favorite one can be calculated to the day of the hour seconds Oh, of course, the specific or needs according to their own needs.

Related Keywords:
Related Article E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD