PHP | date_diff() Function Last Updated : 12 Feb, 2019 Comments Improve Suggest changes Like Article 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:http://php.net/manual/en/function.date-diff.php Comment More infoAdvertise with us Next Article PHP | date_diff() Function R R_Raj Follow Improve Article Tags : Misc Web Technologies PHP PHP-date-time PHP-function +1 More Practice Tags : Misc Similar Reads PHP | DateTime diff() Function The DateTime::diff() function is an inbuilt function in PHP which is used to return the difference between two given DateTime objects. Syntax: Object oriented style: DateInterval DateTime::diff( DateTimeInterface $datetime2, bool $absolute = FALSE ) or DateInterval DateTimeImmutable::diff( DateTimeI 2 min read PHP array_diff() function The array_diff() is an inbuilt function in PHP ans is used to calculate the difference between two or more arrays. This function computes difference according to the values of the elements, between one or more array and return differences in the form of a new array. This function basically returns a 2 min read PHP date_sub() Function The date_sub() function is an inbuilt function in PHP that is used to subtract days, months, years, hours, minutes, and seconds from given date. This function returns a DateTime object on success and FALSE on failure. Syntax: date_sub($object, $interval)Parameters: The date_sub() function accepts tw 2 min read PHP | date_date_set() Function The date_date_set() function is an inbuilt function in PHP which is used to set a new Date. This function has four parameters $object, $year, $month and $day and returns DateTime object on success or false on failure. The date_date_set() function is an alias of DateTime::setDate() function. Syntax: 2 min read PHP array_diff_key() Function This inbuilt function of PHP is used to get the difference between one or more arrays. This function compares the keys between one or more arrays and returns the difference between them. So, the function generally compares two arrays according to their keys and returns the elements that are present 2 min read PHP | easter_date() Function The easter_date() function is a built-in function in PHP which returns the Easter date in the year passed as an argument. The current year is taken as default year when no arguments are passed as parameter. Syntax: easter_date( $year ) Parameter: The function accepts one optional parameter $year whi 2 min read PHP | DateTime sub() Function The DateTime::sub() function is an inbuilt function in PHP which is used to subtract a number of days, months, years, hours, minutes and seconds from a created DateTime object. Syntax: Object oriented style: DateTime DateTime::sub( DateInterval interval ) Procedural style: DateTime date_sub( DateTim 2 min read PHP checkdate() Function The checkdate() function in PHP is an important built-in function used to validate whether a given date is valid or not. It works by checking the values of month, day, and year, and returns true if the date is valid and false otherwise. This is particularly useful when you want to ensure a date is c 2 min read PHP | DateTime add() Function The DateTime::add() function is an inbuilt function in PHP which is used to add an amount of time (days, months, years, hours, minutes and seconds) to the given DateTime object. Syntax: Object oriented style: DateTime DateTime::add( DateInterval $interval ) Procedural style: DateTime date_add( DateT 2 min read PHP | date_parse() Function The date_parse() is an inbuilt function in PHP which is used to find the detailed information about a specified date. This function returns an associative array of detailed information for a specified date on success and returns FALSE on failure Syntax: date_parse($date) Parameters Used: The date_pa 2 min read Like