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))
Method 1: DateName() Function for Day Name DECLARE @DateVal DATE = '2020-07-27'; SELECT @DateVal As [Date], DATENAME(WEEKDAY, @DateVal) AS [Day Name];
The date function DAY accepts a date, datetime, or valid date string and returns the Day part as an integer value.
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
In T-SQL (sqlserver) you can simply do :
getDate()-1
The function substracts (days) as standard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With