0

I have used this to calculate hours , but minutes part is not getting covered.

long businessMillisecondsDiff = BusinessHours.diff(bh.Id,cs.CreatedDate,system.now());
decimal businessHoursDiff = businessMillisecondsDiff / (1000.0*60.0*60.0); 

1 Answer 1

1

It does give you both, you just get minutes as a fraction of hours. If you want minutes only, you can just divide by 60:

Decimal businessMinutesDiff = calculatedDiff / (1000*60);

Or, if you want whole hours and the number of remainder minutes:

Decimal businessMinutesDiff = calculatedDiff / (1000*60);
Decimal hours = businessHours.divide(60).round(RoundingMode.DOWN);
Decimal minutes = businessMinutesDiff - 60 * hours;
6
  • On the same field we want to show both hours and minutes. will it be possible ?
    – Shilpaa
    Commented Jan 11, 2017 at 13:22
  • What's the field type? Text? It should be pretty obvious how to take these last two Decimal values and generate a String.
    – Adrian Larson
    Commented Jan 11, 2017 at 13:23
  • No the field type is number, Length is have given as 10 and decimal 2 .
    – Shilpaa
    Commented Jan 11, 2017 at 13:25
  • So just save the original businessHoursDiff in that...everything after the decimal will be the fraction of a minute elapsed.
    – Adrian Larson
    Commented Jan 11, 2017 at 13:27
  • Er...fraction of an hour. So 1.5 business hours elapsed is the sam as 1 hour, 30 minutes.
    – Adrian Larson
    Commented Jan 11, 2017 at 13:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .