I use this sql to get the start day of the week (Monday) when users enter date of other days
@StartDate has format (yyyymmdd)
SQL: CAST(convert(varchar(12),DATEADD(week,DATEDIFF(week,0,@StartDate),0),112) as int
The problem is that when entered date is from Tuesday to Saturday, it returns to the correct Monday of the current week. Yet when the entered date is sunday, it returns date of monday next week.
can anybody tell me what i did wrong
thank you
Your sunday belongs to same week as monday, this will make monday the first day of the week. It should fix your query
This syntax doesn’t care what day the database is considering first day of the week, it will calculate the monday of the real week of your @StartDate.
You can test with this: