I have a column in my table called status_closed
which is a datetime
column
how can i run a query to select all rows where the status_closed
is not within 24 hours
I have a column in my table called status_closed
which is a datetime
column
how can i run a query to select all rows where the status_closed
is not within 24 hours
Use TIMESTAMPDIFF() function of mysql.
select * from Table where TIMESTAMPDIFF(HOUR,status_closed,NOW())>24;
SELECT *
FROM `table`
WHERE status_closed < NOW() - INTERVAL 1 day
Subtracting a 1 day interval from NOW()
will do the trick:
select
*
from
table
where
status_closed < NOW() - INTERVAL 1 DAY
Use the DATEADD function, and check to see if the status_closed is less than or equal to 24 hours before now.
SELECT * FROM table
WHERE status_closed <= DATEADD(HOUR, -24, GETDATE())