In PHP I have:
$diff = abs(strtotime(date('m/d/Y h:i:s')) - strtotime($latest));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
echo floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
How do I get the difference in seconds? I've tried the following:
$diff = abs(strtotime(date('m/d/Y h:i:s')) - strtotime($latest));
Use DateTime
instead, it will make your code much cleaner.
$latest = new DateTime($latest);
$now = new DateTime();
$diff = $latest->diff($now);
echo $diff->format('%y years %m months %d days');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With