ADVERTISEMENT
ADVERTISEMENT

PHP code to get number of days between two dates

In this code example we are taking two dates and getting their differences, following code can be used to get exact date difference in days between two dates.

Source Code and Output to get number of days between two dates

<?php
$date1 = "2016-07-31";
$date2 = "2016-08-05";

function dateDiff($date1, $date2)
{
    $date1_ts = strtotime($date1);
    $date2_ts = strtotime($date2);
    $diff = $date2_ts - $date1_ts;
    return round($diff / 86400);
}

$dateDiff = dateDiff($date1, $date2);

printf("Difference between in two dates : " . $dateDiff . " Days ");
print "</br>";
?>

Output

Difference between in two dates : 5 Days 

PHP Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.