Home > OS >  How to subtract date-time from current date-time in SQL?
How to subtract date-time from current date-time in SQL?

Time:02-04

I have date-time field in my database like that 2023-01-18 05:43:18 and I want to subtract this field from the current date and time using and sql query to get result when the difference from this field less than one minute .

CodePudding user response:

Use TIMESTAMPDIFF to calculate the difference:

TIMESTAMPDIFF(MINUTE, localtimestamp, columnname) AS difference

localtimestamp gives you the current date and time (without timezone information.) You can also use current_timestamp if you want the timezone.

https://learnsql.com/cookbook/how-to-calculate-the-difference-between-two-timestamps-in-mysql/

  • Related