PHP | date_diff() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report The date_diff() is an inbuilt function in PHP which is used to calculate the difference between two dates. This function returns a DateInterval object on the success and returns FALSE on failure. Syntax: date_diff($datetime1, $datetime2); Parameters: The date_diff() function accepts two parameters as mentioned above and described below: $datetime1: It is a mandatory parameter which specifies the first DateTime object. $datetime2: It is a mandatory parameter which specifies the second DateTime object. Return Value: It returns the difference between two DateTime objects otherwise, FALSE on failure. Below programs illustrate the date_diff() function: Program 1: php <?php // PHP program to illustrate // date_diff() function // creates DateTime objects $datetime1 = date_create('2017-06-28'); $datetime2 = date_create('2018-06-28'); // calculates the difference between DateTime objects $interval = date_diff($datetime1, $datetime2); // printing result in days format echo $interval->format('%R%a days'); ?> Output: +365 days Program 2: php <?php // PHP program to illustrate // date_diff() function // difference only in year $datetime1 = date_create('2017-06-28'); $datetime2 = date_create('2018-06-28'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%a days') . "\n"; // Difference only in months $datetime1 = date_create('2018-04-28'); $datetime2 = date_create('2018-06-28'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%a days') . "\n"; // Difference in year, month, days $datetime1 = date_create('2017-06-28'); $datetime2 = date_create('2018-04-05'); $interval = date_diff($datetime1, $datetime2); echo $interval->format('%R%a days') . "\n"; ?> Output: +365 days +61 days +281 days Reference:https://www.php.net/manual/en/function.date-diff.php Create Quiz Comment R R_Raj Follow 2 Improve R R_Raj Follow 2 Improve Article Tags : Misc Web Technologies PHP PHP-date-time PHP-function +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like