MS SQL Server 2008 :Getting start date and end date of the week to next 8 weeks -
I'm new to SQL, someone can give me a query for this scenario, "let me show the start-up and end The requirement is from today's date to the next 8 weeks. For example, if I select today's date, then it should show
- start date | End date
- 17/03/2012 | 23/03/2012
- 24/03/2012 | 29/03/2012
- .. etc
- 28/04/2012 | 03/05/2013
Try it out:
DECLARE @startDATE DATETIME DECLARE @ current date DATETIME DECLARE @numberOfWeeks INT DECLARE @Dates TABLE (start date time, end date date time) SET @startDate = GETDATE () - '2012-01-01' - whatever you want Set here @ number not check = 8 - set the number of weeks here SET @currentDate = @startdate while @currentDate & lt; Get Started in Date @ (Start date, end date) Date @ @ date (date, date, 6, @ current date) set date @ datedate (day, day, date, 7, @right date); Select end * to date @
This will give you something like this:
Start date expires 21/03/2013 11:22:46 27 / 03/2013 11:22:46 28/03/2013 11:22:46 03/04/2013 11:22:46 04/04/2013 11:22:46 10/04/2013 11:22:46 11 / 04/2013 11:22:46 17/04/2013 11:22:46 18/04/2013 11:22:46 24/04/2013 11:22:46 25/04/2013 11:22:46 01 / 05/2013 11:22:46 02/05/2013 11:22:46 08/05/2013 11:22:46 09/05/2013 11:22:46 15/05/2013 11:22:46 < / Code>
Or if you do not want the time component, you can choose it last:
Choose Convert (VARCHAR, StartDate, 103), Convert (VARCHAR, EndDate, 103) from @dates
Comments
Post a Comment