The effect is as follows:
The code is as follows. It must be noted that: 1. A year is defined as 360 days, and a month is 30 days. 2. In the code, 86400 = 24*60*60, represents the total number of seconds in a day. 3. Both of these time periods must be written in a format similar to. 4. All PHP programs should be promoted, you can change the parameter Get_option ('swt _ builddate') for wordpress to the time parameter to be compared.
The code is as follows: |
Copy code |
<? Php // Get detail gap of year, month and days between two different time by vfhky 20130728 $ Common = (time ()-strtotime (get_option ('swt _ builddate '))); $ A = floor ($ common/86400/360); // An integer year $ B = floor ($ common/86400/30)-$ a * 12; // An 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. "(total". $ d. "days )"; ?> |
Other methods
The code is as follows: |
Copy code |
<? Php Function count_days ($ a, $ B ){ $ A_dt = getdate ($ ); $ 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 ); } // How many days is the difference between today and October 11, 2008? $ Date1 = strtotime (time ()); $ Date1 = strtotime ('2014/1/123 '); $ Result = count_days ($ date1, $ date2 ); Echo $ result; ?> |
Example 2
The code is as follows: |
Copy code |
<? Php // How many days is the difference between today and September 9, 2008? $ Date_1 = date ("Y-m-d "); $ Date_2 = "2008-10-11 "; $ D1 = strtotime ($ Date_1 ); $ D2 = strtotime ($ Date_2 ); $ Days = maid ($ d2-$ d1)/3600/24 ); Echo "today is different from October 11, 2008". $ Days. "day "; ?> |
Summary
From the above example, we can see that mktime and strtotime are actually used. Then, after the calculated time is used for addition and subtraction, we will get the time and date we need.