Skip to content
Advertisement

Get every 2 weeks on particular days SQL Server

I have a query getting the days in particular day that I selected and show the days in a month. My problem is that I need every two weeks of the month. And I also need to get long date format: dddd, dd MMMM yyyy and eliminate the time. Please help me.

The data returned looks like this:

And I need to get like this (every other week):

Advertisement

Answer

By changing your CTE to start on the correct day of the week, you can then change the recursion to add 14 days instead of 1, giving you the desired result without further manipulation:

Output:

Demo on dbfiddle

To change the date format to dddd, dd MMMM yyyy, simply replace the final SELECT with:

Output:

Demo on dbfiddle

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement