How to subtract seconds from current timestamp

10,199

Solution 1

Due to reference you should use SUBTIME

    ...
    and insert_time >= SUBTIME(current_timestamp,'0 0:0:10.000000');

Alternatively you can use INTERVAL as following:

    ...
    and insert_time >= SUBTIME(current_timestamp, INTERVAL 10 SECOND);

Notice that due to reference

When invoked with the INTERVAL form of the second argument, SUBDATE() is a synonym for DATE_SUB().

Solution 2

try this

TIME_TO_SEC(TIMEDIFF(current_timestamp, insert_time)) > 10;
Share:
10,199
Admin
Author by

Admin

Updated on June 15, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm trying to create a query which will get the results that were inserted in the last 10 seconds:

    SELECT *
      FROM table
      WHERE client_id = 1
        AND hash = 'x'
        AND insert_time >= current_timestamp - **10 seconds**
    

    I've been searching how to subtract 10 seconds from the current timestamp, but I didn't succeed yet.