-
Hi,
I need to return a recordset from a table where records are from the last 24 hours. Currenty in a Stored Procedure I have Select .... where [DateTime] > GetDate() -1 which seemed to work quite well until today when it has suddenly been throwing up records from September :mad:.
If anybody has any ideas on a better way of doing this then any help would be appreciated.
Cheers
Shaun
-
Hi S@NSIS
You can use the datediff function to do what you ask
SELECT field1, field2
FROM Table1
WHERE DATEDIFF(hh,field1,GETDATE()) <= 24
GETDATE() is the SQL equivelant of vb's Now()
hope this helps
Ian
-
LOL
Cheers Ian but my code was alright after all. A combination of two many beers last night and American date formats totally confused me this morning!! ;)
Thanks anyway
Shaun
-
it is a bastard tring to program with a hangover from hell, done it enough times myself with some stupid little thing that I couldn't comprehend as I was still pissed from the night before
Ian