You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register
Get Started: AI Resources for Oracle Cloud HCM – Go Here

Progress with Redwood: Redwood Resources for Oracle Cloud HCM -  Go Here

Calculating the Number of Business Days

edited Jun 15, 2018 9:51PM in Reporting and Analytics for HCM 1 comment

Summary

Count the number of Business Days between 2 dates

Content

I constantly get requests to provide reporting based on Business Days rather than Calendar Days. Calculating the difference between 2 Calendar dates is easy: 

 

This example shows 2 days:

Created Date

Closed Date

 

TIMESTAMPDIFF(SQL_TSI_DAY, "Time"."Created Date", "Time"."Closed Date")

No big deal!

 But what if your challenging user asks to exclude weekends (ie Business Days), not so easy. Here’s the magical code that will make you a hero:

 -TIMESTAMPDIFF(SQL_TSI_DAY,TIMESTAMPADD(SQL_TSI_DAY,-(DAYOFWEEK("Time"."Closed Date")-1),"Time"."Closed Date"), TIMESTAMPADD(SQL_TSI_DAY,-(DAYOFWEEK(TIMESTAMPADD(SQL_TSI_DAY,6,"Time"."Created Date"))-1),TIMESTAMPADD(SQL_TSI_DAY,6,"Time"."Created Date")))/7*5+ MOD(7-DAYOFWEEK("Time"."Created Date"),6)+CASE WHEN DAYOFWEEK("Time"."Closed Date")-2>5 THEN 5 ELSE DAYOFWEEK("Time"."Closed Date")-2 END

Tagged:

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!