function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
khushbu dubeykhushbu dubey 

how to calculate working days including holidays every month

Mahesh DMahesh D
Hi Khushbu,

Please look into the below:

Description:
How to calculate the number of working days in the current month and also show the current working day for that month:

Example:
If today is 23rd of Feb

Then

Number of Working days = 20 days (excludes weekends)
Current working day = 16

Resolution This requirement can be achieved by creating 2 formula fields:
Create a Formula field called Working Days with the following formula
 
(
( FLOOR ( ( DATE (
YEAR (DATE (YEAR(TODAY()),MONTH(TODAY()),28)+5),
MONTH(DATE (YEAR(TODAY()),MONTH(TODAY()),28)+5),
1 ) - 1 - DATE (1900,01,01) ) / 7 ) *5 )
+ MIN ( 5, MOD ( DATE (
YEAR (DATE (YEAR(TODAY()),MONTH(TODAY()),28)+5),
MONTH(DATE (YEAR(TODAY()),MONTH(TODAY()),28)+5),
1 ) - 1 - DATE (1900,01,01), 7 ) )
) -
(
( FLOOR ( ( DATE(YEAR(TODAY()),MONTH(TODAY()),1) - DATE (1900,01,01) ) / 7 ) *5 )
+ MIN ( 5, MOD ( DATE(YEAR(TODAY()),MONTH(TODAY()),1) - DATE (1900,01,01), 7 ) )
)

    Create another Formula field called Current Working Day with the following formula

(
( FLOOR ( ( TODAY() - DATE (1900,01,01) ) / 7 ) *5 )
+ MIN ( 5, MOD ( TODAY() - DATE (1900,01,01), 7 ) +1 )
) -
(
( FLOOR ( ( DATE(YEAR(TODAY()),MONTH(TODAY()),1) - DATE (1900,01,01) ) / 7 ) *5 )
+ MIN ( 5, MOD ( DATE(YEAR(TODAY()),MONTH(TODAY()),1) - DATE (1900,01,01), 7 ) )
)

Also look into the below useful information:

https://help.salesforce.com/apex/HTViewSolution?id=000212745&language=en_US

https://sfdcdev.wordpress.com/2011/09/24/handling-holidays-in-salesforce-apex/

https://developer.salesforce.com/forums/?id=906F0000000D75hIAC


How can I calculate business days with a formula field?


http://help.salesforce.com/HTViewSolution?id=000003920 (https://help.salesforce.com/apex/HTViewSolution?id=000212745&language=en_US)

Formula - Weekend Days or Workdays Calculation


https://help.salesforce.com/HTViewSolution?id=000004526 (https://help.salesforce.com/apex/HTViewSolution?id=000212745&language=en_US)

Please do let me know if it helps you.

Regards,
Mahesh
Mahesh DMahesh D
Parker EdelmannParker Edelmann
@khushbu dubey, are you still working on the attendence problem? As a best practice, it's usually better to post as much detail as possible than to just have a question headline. I haven't looked into the specifics of Mahesh's formula, but it's designed to tell you how many business days are in the month, and today's business day number. If you're looking for how many days of the month your employees come to work, this formula won't meet that need.