You need to sign in to do that
Don't have an account?
anketha
Need Business hours to be displayed on the case from the date it was created
Hi,
I have the following code:
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
TimeDiff = hours + ':' + minutes + ':' + seconds;
return TimeDiff;
}
This will return the days:hours:mins:seconds. But if the created date is 25/9/2018, the result is 80:1922:115331:6919867
But I want it to be displayed as 80 days and number of minutes after those many hours and seconds after those many minutes.
I don't want the total number of hours, minutes and seconds from the created date.
Can anyone please help on this?
Regards,
Anketha
I have the following code:
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
TimeDiff = hours + ':' + minutes + ':' + seconds;
return TimeDiff;
}
This will return the days:hours:mins:seconds. But if the created date is 25/9/2018, the result is 80:1922:115331:6919867
But I want it to be displayed as 80 days and number of minutes after those many hours and seconds after those many minutes.
I don't want the total number of hours, minutes and seconds from the created date.
Can anyone please help on this?
Regards,
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.
Thanks for your response on this.
The result of my previous code from the date 25/09/2018 12:43 PM was 81:1937:116237:6974191
And now after I add the newHours,newminutes and newseconds, the result is 81:7:823:74009. I don't think this is correct as well. because I want the minutes and seconds to be within 60.
Regards,
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