Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql get minutes between a datetime and NOW()

Tags:

database

mysql

I'm trying to calculate how many minutes have elapsed between a saved DateTime and NOW(), how can I accomplish this?

like image 325
user391986 Avatar asked Jan 15 '12 11:01

user391986


1 Answers

Use the TIMESTAMPDIFF() built-in function:

SELECT TIMESTAMPDIFF(MINUTE, my_datatime_col, now())

You may have to swap the datetime values to get the right sign (positive/negative) on the result if the column is before/after "now".

like image 119
Bohemian Avatar answered Oct 22 '22 08:10

Bohemian