+ Start a Discussion
Nish321Nish321 

Calculate number of days between two datetime values in apex

Could someone help me out with this? 

integer dt1 = day( datevalue(cc1.ClosedDate) ) - today();
John Pipkin 14John Pipkin 14
Ramshah, 

Use the daysBetween method in the date class:
Integer dt1 = (system.today()).daysBetween(Date.valueOf(cc1.ClosedDate));

 
Mani Sai GundumogulaMani Sai Gundumogula
Date startDate = Date.newInstance(2008, 1, 1);
Date dueDate = Date.newInstance(2008, 1, 30);
Integer numberDaysDue = startDate.daysBetween(dueDate);
Josué PeixotoJosué Peixoto
Very Good @John Pipkin14.
Does work!!!