Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select elapsed time from MySQL

I'm using this query: SELECT NOW() - date AS elapsed FROM ...

Date column is TIMESTAMP. It returns 41632 when elapsed time is about 4 hours and 20 minutes. It's not timestamp. What is it?

Or is there any better way to get elapsed time and generate with PHP like this: "2 minutes ago" "3 hours ago" "yesterday 22:32"

Thanks a lot!

like image 216
ucha Avatar asked Sep 13 '11 17:09

ucha


1 Answers

Use the TimeStampDiff function

  select TIMESTAMPDIFF(MINUTE, NOW(), timestamp_column) FROM my_table 
like image 165
2 revs Avatar answered Sep 28 '22 16:09

2 revs