angeloghiotto Posted September 26, 2011 Share Posted September 26, 2011 What this parameter 'absolute' in DateTime::diff does? I have done some tests but i cant percept what is different when i set this parameter 'true'. Can you explain to me?! Thanks a lot. Best regards. Link to comment https://forums.phpfreaks.com/topic/247865-date_diff-absolute-parameter/ Share on other sites More sharing options...
codeprada Posted September 26, 2011 Share Posted September 26, 2011 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'); ?> Link to comment https://forums.phpfreaks.com/topic/247865-date_diff-absolute-parameter/#findComment-1272785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.