.


Divya

PHP date_diff() function with real time example


In PHP the date_diff() function used to returns the difference between two DateTime.

Syntax

date_diff(datetime1,datetime2,absolute);

Example

<!DOCTYPE html>
<html>
<body>
<?php
$date1=date_create("2017-11-12");
$date2=date_create("2017-12-12");
$diff=date_diff($date1,$date2);
$difference=$diff->format("%R%a days");
echo substr("$difference",1);
?>
</body>
</html>
Output

30 days



.