Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL check if timestamp is greater than 24 hours from now (MYSQL)

Tags:

How to check if timestamp is greater than 24 hours from now with mysql?

DELETE FROM `users` WHERE `time` = ?

Update: date format — 2013-10-24 13:33:23

like image 971
10minutee Avatar asked Oct 26 '13 09:10

10minutee


People also ask

How do I check if a date is greater than today in SQL?

GETDATE() function: This function is used to return the present date and time of the database system. After comparison column contains the following string: Lesser than- If the date is less than today's date. Greater- If the date is greater than today's date.

Can you compare timestamps in SQL?

Can you compare timestamps in SQL? A date, time, or timestamp value can be compared with another value of the same data type, a datetime constant of the same data type, or with a string representation of a value of that data type.

How do I get last 24 hours data in SQL?

In the above SQL query, we use MySQL system function now() to get current datetime. Then we use INTERVAL clause to select those rows where order_date falls within past 24 hours of present datetime. Instead of specifying interval in hours, you can also mention it in day.

What is CURRENT_TIMESTAMP in MySQL?

MySQL CURRENT_TIMESTAMP() Function The CURRENT_TIMESTAMP() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).


2 Answers

Try out this Query:

SELECT * FROM news WHERE date >= now() + INTERVAL 1 DAY;

Feel free to ask

like image 100
Gauttam Jada Avatar answered Oct 21 '22 01:10

Gauttam Jada


try this:

DELETE FROM `users` WHERE `time` >= (NOW() + INTERVAL 1 DAY);

or try this:

DELETE FROM `users` WHERE `time` >= DATE_SUB(CURDATE(),INTERVAL 1 DAY);

or try this:

DELETE FROM `users` WHERE `time` >=  curdate() + interval 1 day

here is a link with some function mysql to manage time
DOCUMENTATION

like image 45
Alessandro Minoccheri Avatar answered Oct 21 '22 01:10

Alessandro Minoccheri