это то, что я делал в своем коде раньше, может быть полезным
$sql ="select datetimecol from table1 where x=y, etc";
$result = mysql_query($sql);
// TODO check for mysql errors
list($datetimecol) = mysql_fetch_row($result);
$timestamp = strtotime($datetimecol);
$diff = time() - $timestamp;
if ($diff < 600) {
// less then 10 minutes
return 'Hot off the press';
} else if ($diff < 3600) {
// less then 1 hour
return sprintf('%d minutes ago', ($diff / 60));
} else if ($diff < 7200) {
// less then 2 hours
return '1 hour ago';
} else if ($diff < 43200) {
// less then 12 hours
return sprintf('%d hours ago', ($diff / 3600));
} else if ($diff < 86400) {
// less then 24 hours and on same day
if (date('j') == date('j', $timestamp)) {
return 'Today';
} else {
return 'Yesterday';
}
} else if ($diff < 172800) {
// less then 48 hours and on next day
if (date('i') == date('j', $timestamp + (60 * 60 * 24))) {
return 'Yesterday';
} else {
return date('l', $timestamp);
}
} else if ($diff < 604800) {
return date('l', $timestamp);
} else {
return date('r', $timestamp);
}