Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to subtract date-time from current date-time in SQL?

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 .

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading