This article mainly introduces PHP to get a given date difference between the days of the method, combined with a specific instance of the form of analysis of the 2 days of date difference calculation method, involving the PHP date string conversion of the relevant operation skills, the need for friends can refer to the next
The example in this article describes how PHP gets the number of days between a given date. Share to everyone for your reference, as follows:
Method One:
<?phpfunction 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);} The difference between today and August 26, 2017 $date1=strtotime (date ("y-m-d")), $date 2=strtotime (' 2017-8-26 '); $result =count_days ($date 1,$ DATE2); Echo $result;? >
Run Result: 187
Method Two:
<?php//today and August 26, 2017 How many days $date_1=date ("y-m-d"), $Date _2= "2017-8-26"; $d 1=strtotime ($Date _1); $d 2=strtotime ($ date_2); $Days =round (($d 2-$d 1)/3600/24); echo "Today differs from August 26, 2017". $Days. " Days ";? >
Operation Result:
Today differs from August 26, 2017 by 187 days