Getdate(), -1 day

N2hvits picture N2hvits · Jan 12, 2016 · Viewed 74k times · Source

I do not understand why, but somehow this query doesn't work. I want to take system date -1 day where the sysdate is smaller by 1 day then current date.

WHERE
    a.SEND_Date >= dateadd(DD,-1,(CAST(getdate() as date) as datetime)) 

Answer

Yahel picture Yahel · Jan 12, 2016

The CAST depends on what kind of date type you need. If you need only to compare dates you can use only:

dateadd(DD, -1, cast(getdate() as date))

If you need to compare with date time you can use:

dateadd(DD,-1,getdate())

That wil give you datetime like this: 2016-01-11 10:43:57.443