Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Posts
    191

    Unanswered: Problem with GETDATE() function.

    Hi everyone,

    DECLARE @altstartdate datetime
    SET @altstartdate = getdate()
    set @altstartdate = @altstartdate -1
    select * from tbl_document where convert(char,dicreationdttm,101) = convert(char,@altstartdate,101)

    The person who wrote the code was trying to get the previous day of data, So today is 03/07/06, within the database it only have data from 03/06/06 and back 15 days, so what I want is data from 03/06 - -2/20, which I believe is 15 days worth of data, How would I go about geting 15 days of data, do I still need to use getdate() function. Any help please. Thanks

    Lystra

  2. #2
    Join Date
    Jul 2004
    Posts
    191
    HELP!!! Please

  3. #3
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Dump your variables and use this instead:
    Code:
    select * from tbl_document where convert(char,dicreationdttm,101) = convert(char,dateadd(day, -1, getdate()),101)
    ...or this, which is more efficient:
    Code:
    select * from tbl_document where dateadd(day, datediff(day, 0, dicreationdttm, 0) = dateadd(day, datediff(day, 0, getdate())-1, 0)
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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