-1

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

user3864924
  • 5
  • 1
  • 7

4 Answers4

1

Use TIMESTAMPDIFF() function of mysql.

select * from Table where TIMESTAMPDIFF(HOUR,status_closed,NOW())>24;
Charvee Shah
  • 730
  • 1
  • 6
  • 21
1
SELECT *
FROM `table`
WHERE status_closed < NOW() - INTERVAL 1 day
George G
  • 7,443
  • 12
  • 45
  • 59
  • 4
    While this answer may solve the problem, you should elaborate on it a bit and explain what your code does. – David Rönnqvist Jul 22 '14 at 14:11
  • 1
    You're wrong, the code describes itself well – George G Jul 23 '14 at 08:39
  • Even if I find a correct code-only answer, I never upvote it because that only rewards/perpetuates the posting of more low-quality answers that care little about educating/empowering thousands of future researchers (who may or may not know a darn thing about the language that they are researching). – mickmackusa Jun 09 '20 at 22:36
  • 1
    Should be the accepted answer. Self-explaining code. – c0dehunter Feb 17 '21 at 21:44
0

Subtracting a 1 day interval from NOW() will do the trick:

select 
  * 
from 
  table 
where 
  status_closed < NOW() - INTERVAL 1 DAY

For further reference

Community
  • 1
  • 1
crthompson
  • 15,653
  • 6
  • 58
  • 80
0

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()) 
Steven
  • 896
  • 2
  • 16
  • 29