I have to get the date collection of every month between two dates. I have no more idea in detail for SQL Server.
Example 1:
If my StartDate is '01/20/2017' (MM/dd/yyyy) and EndDate is '12/20/2017' (MM/dd/yyyy) than the expected result should be as given below.
2017-01-20
2017-02-20
2017-03-20
2017-04-20
2017-05-20
2017-06-20
2017-07-20
2017-08-20
2017-09-20
2017-10-20
2017-11-20
2017-12-20
Example 2:
If my StartDate is '01/30/2017' (MM/dd/yyyy) and EndDate is '12/20/2017' (MM/dd/yyyy) than the expected result should be as given below.
In this example StartDate is '01/30/2017' therefor in February month there is no 30th date in calandar so I need last date of this month. If any leap year will come in the range of these given dates than 29th date will be in result set.
Expected result
2017-01-30
2017-02-28
2017-03-30
2017-04-30
2017-05-30
2017-06-30
2017-07-30
2017-08-30
2017-09-30
2017-10-30
2017-11-30
Thanks in advance.