I want to convert a date string like "19.11.2009 14:00" into the age of it now like "for 2 minutes" or "for 1 week" or "for 2 days"
Is there some code around?
$dateString = strtotime('19.11.2009 14.00'); $now = time(); $time = $dateString - $now; if($time > 60 && $time < 3600) echo $time/60.' minutes remaining'; else if($time > 3600 && $time < 86400) echo $time/3600.' hours remaining'; else if($time > 86400 && $time < 604800) echo $time/86400.' days remaining'; else if($time > 604800 && $time < 18144000) echo $time/604800.' weeks remaining'; else if($time > 18144000 && $time < 217728000) echo $time/18144000.' months remaining'; else if($time > 217728000) echo $time/217728000.' years remaining';
2.1m questions
2.1m answers
60 comments
57.0k users