How to calculate the number of days of different dates in PHP

zhaozj2021-02-16  51

I want to know how much is it from today's N days ago? Or how many days are there in 2002-03-27 and 2001-09-27?

-------------------------------------------------- ------------- First turn the time into the year, month, day, then as follows: $ from = mktime (0,0,0, $ month1, $ day1, $ year1); $ to = MKTIME (0, 0, $ MONTH2, $ Day2, $ YEAR2); $ day_diff = ($ to- $ from) / 86400; how many days are obtained. -------------------------------------------------- ------------- Function dateDiff ($ D1, $ D2 = ") {if (is_string ($ d1)) $ D1 = STRTOTIME ($ d1); if (is_string ($ d2) $ D2 = STRTOTIME ($ D2); Return ($ D2- $ D1) / 86400; Echo Datediff ("2002-03-27", "2001-09-27"). ""; echo datediff ("2002 -03-27 ")." "" "" "" "" "" "" "" "" "" "" "" "" "" "" Is_string ($ d)) $ d = strtotime ($ d); Return Date ("YMD", $ D $ n * 86400);} echo dateadd (10, "2001-09-27"). ""; echo dateadd (-10). "

-------------------------------

How many days is calculated from a certain day?

#### ####

Function nowTime () {

$ DATE = DATE ("m / d / y");

Return $ DATE;

}?>