PHP date_diff() Function

Definition

The date_diff() function returns the difference between two DateTime objects.

Syntax

PHP date_diff() Function has the following syntax.

date_diff(datetime1,datetime2,absolute);

Parameter

ParameterIs RequiredDescription
datetime1Required.DateTime object
datetime2Required.DateTime object
absoluteOptional.TRUE indicates that the interval/difference MUST be positive. Default is FALSE

Return

PHP date_diff() Function returns a DateInterval object on success that represents the difference between the two dates.

PHP date_diff() Function returns FALSE on failure.

Example

Calculate the difference between two dates


<?php/*  w w w . jav  a 2s.  c  om*/
$date1=date_create("2011-03-15");
$date2=date_create("2013-12-12");
$diff=date_diff($date1,$date2);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions