Dear all,
I was wondering if there was an easier way to do what I am trying, without having a table with all the dates and week numbers.
Scenario: Week number of a DateTime Field where the year does not start on January 01<sup>st</sup> but April 1<sup>st</sup> to 31 Mach.
Issue: A week always starts on a Monday so if the 1<sup>st</sup> is on Tuesday, the first week is Tuesday Sunday, if the 1<sup>st</sup> April is on Friday, the 1<sup>st</sup> week is Friday Sunday and 7 day periods from there.
CREATE TABLE [dbo].[DailyCanx](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DateCancelled] [datetime] NULL
) ON [PRIMARY]
ID DateCancelled WeekNo
1 Wed 1st April 2015 1
2 Mon 6th April 2015 2
3 Mon 13th April 2015 3
4 Sun 26th April 2015 4
I could create a table with all the start date and end dates of all the week numbers but I think there must be a better way.
I am based in the UK using SQL Server 2008 R2.
Cheers and thanks for all your time.
Alastair MacFarlane