Results 1 to 4 of 4

Thread: Recordsets from date

  1. #1

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243

    Unhappy

    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 .

    If anybody has any ideas on a better way of doing this then any help would be appreciated.

    Cheers

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  2. #2
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    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

    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  3. #3

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243

    Talking 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
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  4. #4
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    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
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width