suppose the fiscal year is starting from July/1st to June/30th.
I have to calculate the week no. accordingly in SQL Server 2005.
Please Suggest!
Many Tha
If week 1 of your financial year is always 1st July to 7th July...
DECLARE
@inputDate DATETIME,
@fYearStart DATETIME,
@weekNumber INT
SET
@inputDate = getDate()
SET
@fYearStart = DATEADD(year, DATEDIFF(year, '20000101', DATEADD(month, -7, @inputDate)), '20000701')
SET
@weekNumber = DATEDIFF(day, @fYearStart, @inputDate) / 7 + 1
If your finacial weeks are always Sunday to Saturday...
DECLARE
@inputDate DATETIME,
@fYearStart DATETIME,
@weekNumber INT
SET
@inputDate = getDate()
SET
@fYearStart = DATEADD(year, DATEDIFF(year, '20000101', DATEADD(month, -7, @inputDate)), '20000701')
SET
@weekNumber = DATEDIFF(WEEK, @fYearStart, @inputDate)
One or other of these should be adaptable to your definition of week number
.