I have stored a date in database as "15-10-2012",while showing in the front end when the date is not older than one day.I need to show 2 min age , 5 hours ago etc.
how can i achieve this? thanks in advance.
Input
15-10-2012
Output
"2 days ago"
I have stored a date in database as "15-10-2012",while showing in the front end when the date is not older than one day.I need to show 2 min age , 5 hours ago etc.
how can i achieve this? thanks in advance.
Input
15-10-2012
Output
"2 days ago"
See this article http://www.ozzu.com/programming-forum/mysql-selecting-timestamp-from-database-now-minute-t82112.html
And take a look at MYSQL's INTERVAL http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
I think this will help you:
WHERE UNIX_TIMESTAMP(your_date) > (NOW() - INTERVAL 5 MINUTE)
First calculate a unix timestamp from the date, then substract from current time and turn the difference in minutes/hours/days.
list($day,$month,$year) = explode('-', $date);
$time = mktime(0,0,0,$month,$day,$year);
$now = time();
$difference = $now - $time;
$minutes = intval($difference / 60);
$hours = intval($minutes / 60 );
if ($hours > 24) {
$days = intval($hours / 24);
}
(assuming day-month-year)
2 minutes ago:
echo date('j-n-Y', strtotime('15-10-2012') - 120);
Or:
echo date('j-n-Y', strtotime('15-10-2012 -2 minutes'));
Really your starting date should be a timestamp down to the second. If storing just the day/month/year then you'd need to assume each date starts at 00:01