Calculate the time difference our principle is according to the definition 1, the year is 360 days, one months is 30 days; 2, 86400=24*60*60 in the code, representing how many seconds a day the CCP has, so it can be calculated.
The effect is as follows
The code is as follows: 1, the definition of 360 days a year, one months for 30 days, 2, the code of 86400=24*60*60, representing the number of seconds a day, 3, both of these two times to be written in a form similar to the 2013-07-28; 4, extended to all PHP programs, You can change the get_option (' swt_builddate ') this wordpress to retrieve the background data parameters to be compared to the time parameter.
The code is as follows |
Copy Code |
Get detail gap of year,month and days between-different time by Vfhky 20130728 $common = (Time ()-strtotime (get_option (' swt_builddate ')); $a = Floor ($common/86400/360); Integer year $b = Floor ($common/86400/30)-$a *12; Integer month $c = Floor ($common/86400)-$a *360-$b *30; Integer Day $d = Floor ($common/86400); Total number of days echo $a. " Year ". $b." Month ". $c." Day (Total ". $d." Days) "; ?> |
A few other ways
The code is as follows |
Copy Code |
function count_days ($a, $b) { $a _dt=getdate ($a); $b _dt=getdate ($b); $a _new=mktime (12,0,0, $a _dt[' mon '), $a _dt[' mday '], $a _dt[' year '); $b _new=mktime (12,0,0, $b _dt[' mon '), $b _dt[' Mday '], $b _dt[' year '); Return round (ABS ($a _new-$b _new)/86400); } Today and October 11, 2008 How many days difference $date 1=strtotime (Time ()); $date 1=strtotime (' 10/11/2008 '); $result =count_days ($date 1, $date 2); echo $result; ?> |
Example 2
The code is as follows |
Copy Code |
Today and September 9, 2008 How many days difference $Date _1=date ("y-m-d"); $Date _2= "2008-10-11"; $d 1=strtotime ($Date _1); $d 2=strtotime ($Date _2); $Days =round (($d 2-$d 1)/3600/24); echo "Today differs from October 11, 2008". $Days. " Days "; ?> |
Summarize
From the above example we can see that the fact is to use mktime and Strtotime, and then by the calculation of the time to increase and decrease the time we want to come to the date.
http://www.bkjia.com/PHPjc/633125.html www.bkjia.com true http://www.bkjia.com/PHPjc/633125.html techarticle Calculate the time difference our principle is according to the definition 1, the year is 360 days, one months is 30 days, 2, the Code 86400=24*60*60, represents the day the CCP has how many seconds, thus can calculate the effect as ...