function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swamy PSwamy P 

How to convert minutes into hours and days by apex

Hello Team,

We were facing an issue on converting minutes into hours and days. The requirement is like when we have 1520minutes, result must show like 1day1hr20minutes
Usually to convert minutes to hours we will divide by 60. Can anyone help me on showing this result by apex?

Thanks in advance!!
Best Answer chosen by Swamy P
Swamy PSwamy P
My self iam posting the answer also:
                  integer days = mns / 60 / 24 ;
                  integer hours = (mns - days * 60 * 24) / 60 ;
                  integer mins = mns - days * 60 * 24 - hours * 60 ;
                String timeSpentOnCase = days+'Days '+hours+'Hours '+mins+'Minutes';
 

All Answers

Swamy PSwamy P
Main moto is to convert Minutes into "Days Hours Minutes"
Swamy PSwamy P
My self iam posting the answer also:
                  integer days = mns / 60 / 24 ;
                  integer hours = (mns - days * 60 * 24) / 60 ;
                  integer mins = mns - days * 60 * 24 - hours * 60 ;
                String timeSpentOnCase = days+'Days '+hours+'Hours '+mins+'Minutes';
 
This was selected as the best answer