Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate elapsed time in terms of minutes in MySQL

There is a time stamp column/field in a table, and the format is like

2009-12-05 10:35:28,

Now I want to get the time in terms of minutes(How many minutes have elapsed) elapsed from then on, how to do it?

like image 226
Steven Avatar asked Dec 08 '25 10:12

Steven


1 Answers

TIMEDIFF() can be used to get a difference between date/time values, which is expressed in a "HH:MM:SS.SSSSSS" format.

TIME_TO_SEC() can convert this into a number of seconds.

SELECT TIME_TO_SEC(TIMEDIFF(NOW(), my_date_and_timestamp)) / 60;
like image 197
Amber Avatar answered Dec 10 '25 02:12

Amber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!