Skip to content

Instantly share code, notes, and snippets.

Created July 20, 2014 12:56
What would you like to do?
function convert_datetime($datetime, $dateonly = false) {
$values = explode(" ", $datetime);
$dates = explode("-", $values[0]);
$times = explode(":", $values[1]);
$newdate = mktime($times[0], $times[1], $times[2], $dates[1], $dates[2], $dates[0]);
$newdate2 = $_SERVER['REQUEST_TIME']-$newdate;
if ($newdate2>172799 || $dateonly)
return date("F j, Y",$newdate);
else if ($newdate2>86399)
return "Yesterday";
else if ($newdate2>7199)
return intval($newdate2/3600)." hours ago";
else if ($newdate2>3599)
return "1 hour ago";
else if ($newdate2>119)
return intval($newdate2/60)." minutes ago";
else if ($newdate2>59)
return "1 minute ago";
else if ($newdate2>=0)
return "Just a moment ago";
return "In the future";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment