Reply to comment
Week number in a Month
| This is sample code. Add error handling and adjust to your requirements as necessary. |
-- There's simpler and shorter version in the comments below DECLARE @dt DATETIME, @WeekOfMonth TINYINT SET @dt = '2007-07-08' SET @WeekOfMonth = (DAY(@dt) + (DATEPART(dw, DATEADD (MONTH, DATEDIFF (MONTH, 0, @dt), 0)) --^-- The day of the week for the first day of month -1) -- # of days to add to make the first week full 7 days -1)/7 + 1 PRINT @WeekOfMonth
Recent comments
1 week 4 days ago
4 weeks 20 hours ago
4 weeks 23 hours ago
4 weeks 1 day ago
4 weeks 1 day ago
5 weeks 2 days ago
8 weeks 2 days ago
10 weeks 4 days ago
12 weeks 2 days ago
12 weeks 3 days ago