Tuesday, March 20, 2012

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

LystraHELP!!! Please|||Dump your variables and use this instead:select * from tbl_document where convert(char,dicreationdttm,101) = convert(char,dateadd(day, -1, getdate()),101)...or this, which is more efficient:select * from tbl_document where dateadd(day, datediff(day, 0, dicreationdttm, 0) = dateadd(day, datediff(day, 0, getdate())-1, 0)

No comments:

Post a Comment