4
Based on two dates received per parameter, I am trying to list all dates per month (one date per month) based on the start date and up to the end date. These dates returned have to check the day of the week of the start date and the number of the week, to replicate that date for all months.
For example, @StartDate = 2016/04/15
and @EndDate = 2016/09/01
, I note that the @StartDate
is on a first Friday in April, so until @EndDate
would date all the first Friday of each month:
2016/05/06
2016/06/03
2016/07/01
2016/08/05
In case @StartDate = 2016/04/12
and @EndDate = 2016/09/01
, I note that the @StartDate
is on the second Tuesday of the month of April, then would pick up every Monday Tuesdays of each month:
2016/05/10
2016/06/14
2016/07/12
2016/08/09
In case @StartDate = 2016/04/28
and @EndDate = 2016/09/01
, I note that the @StartDate
is last week to Thursday in April:
2016/05/26
2016/06/30
2016/07/28
2016/08/25
In the latter case he would have to take into account the number of weeks of each month, since there are months with 4 and another with 5 weeks.
It seems to go a little bit along the lines of what I want, but for example, to fit into
@starDate = '2016/02/01'
ends up picking up only the Monday in the first week of the months, and in the month of March (for example) there is no 2nd week in the first week. I wanted to be able to return the first second in the month– CesarMiguel
I fixed the calculation of the @weekmonth variable to return the number of the week corresponding to the start date.
– ricidleiv
@exact rocodleiv, end up not working for on days at the end of the month. The example of choosing the
@startDate = '2016/03/31';
, is the last Thursday of the month (in this case March), for the next months has to pick up the last Thursday of the month, having or not the day 31– CesarMiguel
Indeed, there are many criteria to consider. I believe it is easier for you to have a Date table example, with pre-calculated fields ("last day of the week in the month", "number of the week in the month" etc).
– ricidleiv