Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to find the number of days between given two dates in php?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 387
    Comment on it

    Hi Readers,
     Welcome to FindNerd, today we are going to discuss how to find the number of days between given two dates in PHP?

     If you want to calculate the difference between two dates then you should use date_diff() function for finding the difference. This function always returns DateInterval object on success which represents difference between two dates and returns FALSE  on failure.

     

    Note:-You can use this function only PHP 5.3 or above version.

    Syntax of date_diff() function:

    date_diff(datetime1,datetime2,absolute);

    There are 3 parameter available on above syntax, datetime1,datetime2 is required and absolute is optional parameter.

     

    You can see below example

    <?php
          //here create first date
           $DateTime1 = new DateTime("2016-03-04");
           //here create second date
           $DateTime2 = new DateTime("2015-07-04");
           //call here date_diff() function
           $DiffDay=date_diff($DateTime1,$DateTime2);
            //print different days
            echo $DiffDay->format("%a days");
    ?>

    output will come following:

    244 days

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: