I am trying to calculate difference between to dates in formula field on start and end date. I am not getting accurate value.
I should calculate hours in weekdays that is Monday to Friday and 9 AM to 6 PM EST between given dates
below is my formula:
ROUND( 9 * (
( 5 * FLOOR( ( DATEVALUE( End_Date_Time__c ) - DATE( 1900, 1, 8) ) / 7) +
MIN(5,
MOD( DATEVALUE( End_Date_Time__c ) - DATE( 1900, 1, 8), 7) +
MIN( 1, 24 / 9 * ( MOD( End_Date_Time__c - DATETIMEVALUE( '1900-01-08 14:00:00' ), 1 ) ) )
)
)
-
( 5 * FLOOR( ( DATEVALUE( Start_Date_Time__c ) - DATE( 1900, 1, 8) ) / 7) +
MIN( 5,
MOD( DATEVALUE( Start_Date_Time__c ) - DATE( 1996, 1, 1), 7 ) +
MIN( 1, 24 / 9 * ( MOD( Start_Date_Time__c - DATETIMEVALUE( '1900-01-08 14:00:00' ), 1) ) )
)
)
),
0 )
In some scenarios I am getting expected results but in most not correct values.