Find records produced in the last hour

Posted by justSteve on Stack Overflow See other posts from Stack Overflow or by justSteve
Published on 2010-06-08T16:45:04Z Indexed on 2010/06/08 16:52 UTC
Read the original article Hit count: 152

Filed under:

I have a smalldatetime field named myTime recording when the record was created. I need the syntax that selects records created within the last hour.

thought it would be:

and DATEDIFF("hh", datePart(hh, myTime), DatePart(hh, GETDATE()) < 1

where datediff 1) looks for hours; 2) looks at the hours portion of the data in myTime as starting; 3) looks at the hours portion of now for ending 3) produces an int that gets compared to '1'

the results i'm getting are clearly way, way off base cuz umm...clearly...i don't know what i'm doing.

help? thx

© Stack Overflow or respective owner

Related posts about tsql