DEV Community

mhsohag11
mhsohag11

Posted on

Answer: How to display total number of days between two dates using php

Use the DateTime class and compare them via diff() method. $date1->diff($date2). The output will give you an accurate result of days:

$date1 = new DateTime('2018-01-01');
$date2 = new DateTime('2018-02-15');

print_r($date1->diff($date2));

Output:

DateInterval Object 
( 
[y] => 0 
[m] => 1 
[d] => 14 
[h] => 0 
[i] => 0

Top comments (0)