How to get last date of the lastweek in sql? I mean last sunday date using query?
SQL Server EOMONTH() overview The EOMONTH() function returns the last day of the month of a specified date, with an optional offset. The EOMONTH() function accepts two arguments: start_date is a date expression that evaluates to a date. The EOMONTH() function returns the last day of the month for this date.
Option 1: Sunday as the First Day of the Week DATEADD(week, DATEDIFF(week, -1, RegistrationDate), -1) AS Sunday; The function DATEADD() takes three arguments: a datepart, a number, and a date.
Regardless of the actual DATEFIRST setting, the last Sunday could be found like this:
SELECT DATEADD(day, -1 - (DATEPART(weekday, GETDATE()) + @@DATEFIRST - 2) % 7, GETDATE() ) AS LastSunday
Replace GETDATE()
with a parameter @date
to get the last Sunday before a particular date.
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