Skip to content

Instantly share code, notes, and snippets.

@ijason
Created September 14, 2017 15:36
Show Gist options
  • Save ijason/55976c9b4458e614217eaecbdaa044b1 to your computer and use it in GitHub Desktop.
Save ijason/55976c9b4458e614217eaecbdaa044b1 to your computer and use it in GitHub Desktop.
Salesforce formula to find the number of hours between two date/times excluding weekends.
ROUND(24*(
(5*FLOOR((TODAY()-DATE(1996,01,01))/7) +
MIN(5,
MOD(TODAY()-DATE(1996,01,01), 7) +
MIN(1, (MOD(NOW()-DATETIMEVALUE('1996-01-01 00:00:00'), 1)))
))
-
(5*FLOOR((DATEVALUE(NULLVALUE(Last_Activity_Date__c, CreatedDate))-DATE(1996,01,01))/7) +
MIN(5,
MOD(DATEVALUE(NULLVALUE(Last_Activity_Date__c, CreatedDate))-DATE(1996,01,01), 7) +
MIN(1, (MOD(NULLVALUE(Last_Activity_Date__c, CreatedDate)-DATETIMEVALUE('1996-01-01 00:00:00'), 1)))
))
), 0)
@MitulShah23
Copy link

Hi, It is not working. for example, I have two date-time fields start date and end date. So, where do I replace that field in your code? Please let me know as soon as possible.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment