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
Share:
19,015
Dad Daniel
Author by

Dad Daniel

Updated on July 27, 2022

Comments

  • Dad Daniel
    Dad Daniel almost 2 years

    I'm looking for a way to Subtract 24hrs in T-SQL from Today's Date

    Thanks!

  • marc_s
    marc_s over 13 years
    If 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
    marc_s over 13 years
    works - 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
    veljkoz over 13 years
    well, if you use it all the time, than you won't forget, but in general, I have to agree with you
  • Chris
    Chris over 13 years
    Sorry kind of new posting on this site.
  • Michael B
    Michael B almost 12 years
    This subtracts 1 day. NOT 24 hours. Huge difference.
  • veljkoz
    veljkoz almost 12 years
    @Kyle: How is it different exactly? Some example maybe?