Calculate difference between two Dates Using Php

For calculating the day difference between two dates using Php. we already have a function for this in Php which can give us the date difference, the Function Named as date_diff().

So, let's look into the PHP date_diff() function basics and what are the parameters required to for the execution of the PHP date_diff() function. 

Basic Syntax:
date_diff(datetime1, datetime2, absolute)


In PHP date_diff() function first, two parameters are required and the third one is optional.which accepts the boolean value and by default, it's 'False'.

Let's take example to see the difference between dates:


<?php
    $startdate = date_create("2020-03-24");
    $enddate = date_create("2020-04-22");
    $difference = date_diff($date1, $date2);
    echo $difference->format("%R%a days");
?>

Output:

+29 days

1 comment:

  1. You have made your points in a smart way. I am impressed with how interesting you have been able to present this content. Thanks for sharing nice information.

    Best Institute for C++ Training Course in Delhi, India
    C++ Training Institute in Delhi

    ReplyDelete

If you have any doubts regarding the post. Please let me know.