Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

date_diff()

Example

Compute the difference between two dates.

<?php
$date1=date_create(“2013-03-15”);
$date2=date_create(“2013-12-12”);
$diff=date_diff($date1,$date2);
?>

Definition and Usage

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

Syntax

date_diff(datetime1, datetime2, absolute)

Parameter Values

 

Parameter

Description

datetime1

Required. Specifies a DateTime object.

datetime2

Required. Specifies a DateTime object.

absolute

Optional. Specifies a Boolean value. TRUE ensures that the interval/difference is always positive. The default is FALSE.

Technical Details

Return Value:

Returns a DateInterval object representing the difference between the two dates on success; FALSE on failure.

PHP Version:

5.3+