|
|
Question : Week of month...
|
|
Is there anyway to figure out how many weeks are in a month and what week of the month it is with a specific date in an sql statement???
|
Answer : Week of month...
|
|
on the assumption that you are happy to use the servers definition on the start of the week and that this sybase code will work on ms-sql (which it amost always does)
lets assume that @dt is any given date.
DECLARE @dt datetime SELECT @dt = getdate()
SELECT weekno = 1 + datediff(wk,dateadd(dd,1 - datepart(dd,@dt),@dt),@dt) SELECT weeksinmonth = datediff(wk,dateadd(dd,1 - datepart(dd,@dt),@dt), dateadd(mm,1,dateadd(dd,1 - datepart(dd,@dt),@dt)))
based on full weeks in the month
|
|
|
|
|