This is worked out by the following steps:
1. Take the differences between the start and the current date and divide by 7
2. Which gives a whole number and a remainder e.g. 18/7 = 2.6
3. Take the whole number and multiply by five e.g. 2 * 5 = 10
4. Take the remainder and multiply by 10 e.g. 0.6 * 10 = 6
5. Where I’m stuck… if the multiplied remainder is over 5 then round down to 5 e.g. 6 > 5 = 5
6. Sum the two numbers plus 1 and divide by 3 e.g. (10 + 6 + 1) / 3 = 5.6
7. Round up to a whole number e.g. 5.6 = 6
Code:
Steps 1 - 3
Code: Select all
ROUND((FLOOR(DAY_DIFFERENCE(FIRST_DAY_OF_MONTH(CURRENT_DATE),CURRENT_DATE+6) / 7) * 5 +
Steps 4 - 5
Code: Select all
ROUND(DAY_DIFFERENCE(FIRST_DAY_OF_MONTH(CURRENT_DATE),CURRENT_DATE+6) / 7 -
FLOOR(DAY_DIFFERENCE(FIRST_DAY_OF_MONTH(CURRENT_DATE),CURRENT_DATE+6) / 7),1) * 10
Code: Select all
+ 1 ) / 3 , 0)
I'm thinking I may just have to create something in SQL and then import it into a BO to set the values for the query, but ideally I would like one piece of code that could filter the period. Does anyone know how I can do this?
Whole Statement
Code: Select all
ROUND((FLOOR(DAY_DIFFERENCE(FIRST_DAY_OF_MONTH(CURRENT_DATE),CURRENT_DATE+6) / 7) * 5 +
ROUND(DAY_DIFFERENCE(FIRST_DAY_OF_MONTH(CURRENT_DATE),CURRENT_DATE+6) / 7 -
FLOOR(DAY_DIFFERENCE(FIRST_DAY_OF_MONTH(CURRENT_DATE),CURRENT_DATE+6) / 7),1) * 10 + 1 ) / 3 , 0)