PHP program to find the total number of date between any two given dates

PHPServer Side ProgrammingProgramming

The ‘date_diff’ function can be used to get the difference between two dates. It is a built-in function that returns a DateInterval object if a specific number of days has been found, and returns False if the days is not found.

Example

 Live Demo

<?php
$date_1 = date_create('23-11-2019');
$date_2 = date_create('22-1-2020');
$day_diff = date_diff($date_1, $date_2);
echo $day_diff->format('The day difference is: %R%a days');
?>

Output

The day difference is: +60 days

Two dates are defined using the ‘date_create’ function and the difference/ the number of days that are present between these two dates can be computed using the ‘date_diff’ function. It is assigned to a variable and printed on the console.

raja
Published on 02-Jul-2020 06:37:55
Advertisements