Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 number of week for a month

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2009-03-10 : 03:47:10
Hi can anyone help in how to find number of weeks for a given month
week day starting: saturday
week day ending : friday

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-10 : 04:13:03
[code]
DECLARE @Month int,@StartDate datetime,@EndDate datetime,@Weeks int
SET @Month=5--example value
SELECT @StartDate=DATEADD(mm,@Month-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)),
@EndDate=DATEADD(mm,@Month,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))-1,
@Weeks=DATEPART(wk,@EndDate)-DATEPART(wk,@StartDate)+1

[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-10 : 04:14:51
FULL weeks, or included weeks?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2009-03-10 : 10:39:31
It would be helpful if you provided a real example using a real month of how each week would be numbered, along with the start date and end date for each week number. April 2009 would be a good example.




CODO ERGO SUM
Go to Top of Page
   

- Advertisement -