PDA

Click to See Complete Forum and Search --> : Recordsets from date


S@NSIS
Oct 5th, 2000, 06:33 AM
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

Ianpbaker
Oct 5th, 2000, 08:03 AM
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

S@NSIS
Oct 5th, 2000, 09:25 AM
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

Ianpbaker
Oct 5th, 2000, 09:30 AM
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