How does PHP get the number of days difference between two dates?
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:
02 |
function count_days( $a , $b ){ |
" |
; $a _new =  mktime $a _dt [ ' Mon ' ], $a _dt [ ' mday ' ],  $a _dt [ ' year ' ); |
" |
; $b _new =  mktime $b _dt [ ' Mon ' ], $b _dt [ ' mday ' ],  $b _dt [ ' year ' ); |
07 |
return round ( abs ( $a_new - $b_new )/86400); |
11 |
$date1 = strtotime (time()); |
12 |
$date2 = strtotime ( ‘10/11/2008‘ ); |
13 |
$result = count_days( $date1 , $date2 ); |
The second type:
3 |
$Date_1 = date ( "Y-m-d" ); |
5 |
$d1 = strtotime ( $Date_1 ); |
6 |
$d2 = strtotime ( $Date_2 ); |
7 |
$Days = round (( $d2 - $d1 )/3600/24); |
8 |
echo "今天与2008年10月11日相差" . $Days . "天" ; |
How does PHP get the number of days difference between two dates?