How to find number of days between two Dates in Apex?

How to find number of days between two Dates in Apex?

Sample Code:

public Integer temp;
public Date objDT = Date.Today().addDays( -10 );
temp = objDT.daysBetween( Date.Today() ); // Returns No. of days between objDT and today which is 10
System.debug( 'temp value is ' + temp );
System.assertEquals( 10, temp );

Output:

Leave a Reply