Answers for "Apex Date Difference"

0

Apex Date Difference

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);
Posted by: Guest on September-17-2021

Browse Popular Code Answers by Language