
Hi Anketha, Try the following code it may be helpful for you:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.Thanks and Regards,Deepali Kulshrestha.public static string getBusinessHours(ID CaseId){
string TimeDiff;
BusinessHours bh = [SELECT Id FROM BusinessHours WHERE IsDefault=true];
Case c = [Select id,CreatedDate from case where id=:CaseId];
Datetime CurrentDateTime = System.now();
Datetime CreatedDateTime = c.CreatedDate ;
//Datetime ClosedDateTime = ncs[i].ClosedDate ;
//Datetime ClosedDateTime =ncs[i].LastModifiedDate;
Decimal diffHours = BusinessHours.diff(bh.ID,CreatedDateTime,CurrentDateTime);
Decimal days= (diffHours/86400000).round(); // converting milliseconds into days
Decimal hours = (diffHours/3600000).round(); // converting milliseconds into Hours
Decimal minutes = (diffHours/60000).round(); // converting milliseconds into minutes
Decimal seconds = (diffHours/1000).round(); // converting milliseconds into seconds
Decimal newHours=days*24-hours;
Decimal newminutes=((24*days*60)+newHours*60)-minutes;
Decimal newseconds=((24*days*60*60)+(newHours*60+newminutes*60))-seconds;
TimeDiff = days +':'+ newHours + ':' + newminutes + ':' + newseconds;
return TimeDiff;
}
3 answers