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. Quote 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'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/247865-date_diff-absolute-parameter/#findComment-1272785 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.