Mysql gets minutes between datetime and NOW ()

I am trying to calculate how many minutes have passed between the stored DateTime and NOW (), how can I do this?

+7
source share
4 answers

Use this:

SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(datetime_col) 
+7
source

Use the TIMESTAMPDIFF() built-in function:

 SELECT TIMESTAMPDIFF(MINUTE, my_datatime_col, now()) 

You may need to change the datetime values ​​to get the correct sign (positive / negative) as a result if the column is before / after "now."

+20
source

Just find the TIMEDIFF function in your MySQL docs.

+1
source

One way is to use the UNIX era (according to rkosegi and Holger Just)

 SELECT ROUND((UNIX_TIMESTAMP() - UNIX_TIMESTAMP(datefield))/60); 
0
source

All Articles