generate functionSun, 25 Dec 2022

convert "March 27, 2018" to time and return time ago

function timeago($date){ $timestamp = strtotime($date); $strTime = array("second", "minute", "hour", "day", "month", "year"); $length = array("60","60","24","30","12","10"); $currentTime = time(); if($currentTime >= $timestamp) { $diff = time()- $timestamp; for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) { $diff = $diff / $length[$i]; } $diff = round($diff); return $diff . " " . $strTime[$i] . "(s) ago "; } }

Questions about programming?Chat with your personal AI assistant