top of page

Calculate Days between two Date fields in Salesforce

Using Formula


The below formula return the number of days between two Fields. Create a formula field and select data type as Number and then put the below formula :-


TODAY() - DATEVALUE(dateField1)


OR


DATEVALUE(dateField1) - DATEVALUE(dateField2)


ex : 8/1/2021 - 7/8/2021

Output : 24


Using Apex Code


Date startDate = Date.today();

Date endDate = Date.today().addDays(10);

Integer noOfDays = startDate.daysBetween( endDate );

system.debug( 'Output is ' + noOfDays );


Output : 10

370 views0 comments

Recent Posts

See All
bottom of page