Calculating time difference between 2 dates in minutes

前端 未结 4 2000
无人共我
无人共我 2020-12-03 00:09

I have a field of time Timestamp in my MySQL database which is mapped to a DATE datatype in my bean. Now I want a query by which I can fetch all records in the

相关标签:
4条回答
  • 2020-12-03 00:55
    ROUND(time_to_sec((TIMEDIFF(NOW(), "2015-06-10 20:15:00"))) / 60);
    
    0 讨论(0)
  • 2020-12-03 00:59

    Try this one:

    select * from MyTab T where date_add(T.runTime, INTERVAL 20 MINUTE) < NOW()
    

    NOTE: this should work if you're using MySQL DateTime format. If you're using Unix Timestamp (integer), then it would be even easier:

    select * from MyTab T where UNIX_TIMESTAMP() - T.runTime > 20*60
    

    UNIX_TIMESTAMP() function returns you current unix timestamp.

    0 讨论(0)
  • 2020-12-03 01:05

    I am using below code for today and database date.

    TIMESTAMPDIFF(MINUTE,T.runTime,NOW()) > 20

    According to the documentation, the first argument can be any of the following:

    MICROSECOND
    SECOND
    MINUTE
    HOUR
    DAY
    WEEK
    MONTH
    QUARTER
    YEAR
    
    0 讨论(0)
  • 2020-12-03 01:11

    I think you could use TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) something like

    select * from MyTab T where
    TIMESTAMPDIFF(MINUTE,T.runTime,NOW()) > 20
    
    0 讨论(0)
提交回复
热议问题