date - Error (?) in Day counting PHP -



date - Error (?) in Day counting PHP -

<?php $date1 = "2002-1-1"; $date2 = "2021-12-31"; $deff = abs(strtotime($date2) - strtotime($date1)); $daycount = $deff / (60 * 60 * 24); echo $daycount; ?>

why reply 7304 instead of 7300 trying calculate number of days 20 years?

please help.

use datetime this:

$datetime1 = new datetime("2002-1-1"); $datetime2 = new datetime("2021-12-31"); $interval = $datetime1->diff($datetime2); $elapsed = $interval->format('%a days'); echo $elapsed;

see in action

reference

datetime dateinterval

php date datetime date-math

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -