Jump to content

date_diff - absolute parameter


angeloghiotto

Recommended Posts

The absolute number of every number is returned. Meaning that you won't get a negative value when the date passed is lesser than the one being compared.

 

Example

<?php
#slight modification of the example on php.net
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$nonabsolute = $datetime2->diff($datetime1);
$absolute = $datetime2->diff($datetime1, true);
echo 'Regular: ' . $nonabsolute->format('%R%a days') . '<br>';
echo 'Absolute: ' . $absolute->format('%R%a days');
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.