We often need to get the number of days between two dates to make it easier for customers to know how many days are different from a certain time period, so the results are now becoming more and more popular. No longer shows the date as stiff as it used to be. We've shared here two ways to get the number of days between two dates.
The first type:
<?phpfunction count_days ($a, $b) {$a _dt = getdate ($a); $b _dt = getdate ($b); $a _new = mktime (0, 0, $a _dt[' mon '), $a _dt[ ' Mday '], $a _dt[' year '); $b _new = mktime (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 $date1 = Strtotime (Time ()), $date 2 = strtotime (' 10/11/2008 '); $result = Count_days ($date 1, $date 2) ; Echo $result;? >
The second type:
<?php//today differs from September 9, 2008 by how many days $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. "Day";? >
How does PHP get the number of days difference between two dates?