3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function get_age($date, $units='years') { $modifier = date('n') - date('n', strtotime($date)) ? 1 : (date('j') - date('j', strtotime($date)) ? 1 : 0); $seconds = (time()-strtotime($date)); $years = (date('Y')-date('Y', strtotime($date))-$modifier); switch($units) { case 'seconds': return $seconds; case 'minutes': return round($seconds/60); case 'hours': return round($seconds/60/60); case 'days': return round($seconds/60/60/24); case 'months': return ($years*12+date('n')); case 'decades': return ($years/10); case 'centuries': return ($years/100); case 'years': default: return $years; } } echo 'I am '.get_age('September 19th, 1984', 'days').' days old';
based on 7gvpS
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
I am 10970 days old