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

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



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.

Updated on: 2020-07-02T06:38:28+05:30

215 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements