xxxxxxxxxx
DateTime startDate = DateTime.newInstance(2020,1,1,3,0,0);
DateTime endDate = DateTime.newInstance(2020,1,3,6,0,0);
Decimal minutes = Integer.valueOf((endDate.getTime() - startDate.getTime())/(1000*60));
System.debug('Minutes : ' + minutes);
Decimal hours = Integer.valueOf((endDate.getTime() - startDate.getTime())/(1000*60*60));
System.debug('Hours : ' + hours);
Decimal days = Integer.valueOf((endDate.getTime() - startDate.getTime())/(1000*60*60*24));
System.debug('Days : ' + days);
xxxxxxxxxx
Datetime startDate = system.now();// Start date
Datetime endDate = system.now().addHours(60);//End Date
Integer noOfDays = startDate.Date().daysBetween(endDate.Date());
System.debug('No Of Days : '+noOfDays);
Datetime sameDayEndDate = startDate.addDays(noOfDays);
System.debug('Same Day : '+sameDayEndDate);
Decimal decHours = ((endDate.getTime())/1000/60/60) - ((sameDayEndDate.getTime())/1000/60/60);
System.debug('Dec Hours : '+decHours);
decimal decMinutes = ((endDate.getTime())/1000/60) - ((sameDayEndDate.getTime())/1000/60);
System.debug('Minutes : '+decMinutes);