Calculating time difference between 2 dates in minutes

前端 未结 4 2010
无人共我
无人共我 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: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.

提交回复
热议问题