Subtract 24hrs in T-SQL from Today's Date
19,015
Solution 1
SELECT GETDATE() - 1
The -1
substracts one day from current date (GETDATE()
)
Solution 2
DECLARE @Now datetime, @Calc datetime
SET @Now = GetDate()
SET @Calc = DateAdd(hh, -24, @Now)
Solution 3
select dateadd(d,-1,GETDATE())
Solution 4
SELECT DATEADD(dd, -1, GETDATE()) AS yesterday
Author by
Dad Daniel
Updated on July 27, 2022Comments
-
Dad Daniel almost 2 years
I'm looking for a way to Subtract 24hrs in T-SQL from Today's Date
Thanks!
-
marc_s over 13 yearsIf you post code or XML, please highlight those lines in the text editor and click on the "code" button (101 010) on the editor toolbar to nicely format and syntax highlight it!
-
marc_s over 13 yearsworks - but seems a bit unintuitive; to me, it's not obvious right from the get go that the -1 is "-1 day" .... I'd rather be explicit
(DATEADD(D, -1, GETDATE())
- makes it easier to read (for others, and for you in a year or two) and helps with maintenance... -
veljkoz over 13 yearswell, if you use it all the time, than you won't forget, but in general, I have to agree with you
-
Chris over 13 yearsSorry kind of new posting on this site.
-
Michael B almost 12 yearsThis subtracts 1 day. NOT 24 hours. Huge difference.
-
veljkoz almost 12 years@Kyle: How is it different exactly? Some example maybe?