+ Start a Discussion
Santosh Shahi04807505290019439Santosh Shahi04807505290019439 

I want to calculate business hours between two dates , how we will calculate it by apex code ,(business hours standard object)

The below posts might help


I think this is the method you're looking for:

BusinessHours.diff(String businessHoursId, Datetime startDate, Datetime endDate)

For more info you might want to just look up the BusinessHours Class in the standard Apex reference:

Carolina Ruiz MedinaCarolina Ruiz Medina
Hi Santos,
I had the code below,   that maybe it could help. However I like more the use of BusinessHours class. The solution that @Martha_Senete suggested is nice. ( I clicked like on that answer :) ) 

-->Datetime startDate = datetime.newInstance(2014, 01, 01, 10, 0, 0 );
--> Datetime endDate = datetime.newInstance(2014, 01, 01, 18, 0, 0);

public Time calculateBusinessHours(Datetime startDate, Datetime endDate)
        Long businessHours = endDate.getTime() - startDate.getTime();
        return dateTime.newInstance(businessHours).time();


Anyway Hope this help too.

Kind Regards,