Find the month to which date belongs to
Posted on 2017-03-28
I am trying to implement a solution to the problem using SQL (DB2).
A month is defined based on below condition :
If 1st of month is on a Wednesday or earlier, then that corresponding Monday marks the beginning of the month
Say : Mar 1 2017 was a Wednesday so the month 201703 will start from 28th Feb.
If 1st of month is on a Thursday or later, then the next Monday marks the beginning of the month.
Say : Apr 1 2017 is a Saturday so the month 201704 will start from 3rd April.
Now based on the logic, I need to update the month for each and every date in a table. The date could be of any value. Accordingly to above month definition, I should update the month value.
Say 28-03-2017 should belong to 201703 , 01-04-2017 should still belong to 201703 etc.
could someone advise.