Intro
If you need to calculate the date difference between two dates for weekdays/business days, this can be done in Beast Mode or SQL DataFlow using a query.SQL Query
Copy and paste the following SQL query into your Beast Mode or DataFlow. ReplaceStart Date and End Date with the corresponding columns from your data.
Solution Details and Steps
- If the Start Date and End Date are the same, then it will return 0
- If Start Date and End Date aren’t the same, then the End Date is moved to Friday and Start Date is moved to Monday when either occurs on a weekend. Then, subtract them to find the date difference. This removes any weekend days from the Start and End Dates.
- If the week number of the Start Date is equal to the week number of the End Date, then return
- If they are not the same week, then return the week number of the End Date.
- If the week number of the Start Date is equal to the week number of the End Date, then return
- If they are not the same week, then return the week number of the Start Date. This week number is subtracted from the End Date week number calculated in step 3. Then, we multiply by 2. This outputs the total number of weekend days that occur within the Start and End Date range.
- Lastly, the total number of weekend days is subtracted from the date difference calculated above in step 2.
Note: The SQL Query only works if the dates are within the same year. If you need to compare dates in different years, use the Magic ETL method instead.
Magic ETL
- Connect your Input DatSet tile to a Date Operations tile.
-
Configure the tile as shown here:
Note: In Step 4, you will want to make sure to choose your end date first and then your start date as this function subtracts the dates from each other. If you enter the start date first it will result in a negative number.
