Activity Forums Salesforce® Discussions How to calculate days between two DateTime values excluding weekends?

  • Surbhi

    Member
    May 30, 2016 at 11:55 am

    Hi Himanshu,

    You can use the below formula:

    CASE(MOD( StartDate__c - DATE(1985,6,24),7),

    0 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,4,4,5,5,5,6,5,1),
    1 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,4,4,4,5,4,6,5,1),
    2 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,3,3,3,4,3,5,4,6,5,1),
    3 , CASE( MOD( EndDate__c - StartDate__c ,7),1,2,2,2,3,2,4,3,5,4,6,5,1),
    4 , CASE( MOD( EndDate__c - StartDate__c ,7),1,1,2,1,3,2,4,3,5,4,6,5,1),
    5 , CASE( MOD( EndDate__c - StartDate__c ,7),1,0,2,1,3,2,4,3,5,4,6,5,0),
    6 , CASE( MOD( EndDate__c - StartDate__c ,7),1,1,2,2,3,3,4,4,5,5,6,5,0),
    999)
    +
    (FLOOR(( EndDate__c - StartDate__c )/7)*5)

    Thanks

  • Parmanand Shete

    Member
    December 24, 2019 at 9:48 am

    (5 * FLOOR( ( DATEVALUE(End_Date__c) - DATE( 1900, 1, 8) ) / 7 ) + MIN( 5, MOD( DATEVALUE(End_Date__c) - DATE( 1900, 1, 8), 7 ) ) ) - (5 * FLOOR( ( DATEVALUE(Start_Date__c) - DATE( 1900, 1, 8) ) / 7 ) + MIN( 5, MOD( DATEVALUE(Start_Date__c) - DATE( 1900, 1, 8), 7 ) ) )

    Here Start_Date__c is earlier date and End_Date__c is new one which is less than Start_Date__c

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos