How to calculate days from the date in Salesforce?

551    Asked by NakanoHase in Salesforce , Asked on Aug 22, 2021

I'm looking for a way to calculate the days, here below is my requirement:

If the calendar interval is 90 days and the LastCompletionDate is 04/05/2015 then find the # of days.

Here is what I have gathered.

String CalendarInterval = 90; //days; Date daysDiff = CalendarInterval - LastCompletionDate; //04/05/2015 If the DaysDiff >= 90 { //create entry in Order Object }
Answered by Prateek Jain

You didn’t mention 90 days from when? I guess from today/now? If that's the case then you can use the daysBetween method and calculate that easily:

  Date startDate = LastCompletionDate; Date dueDate = System.today(); Integer daysBetween = startDate.daysBetween(dueDate); if (daysBetween >= CalendarInterval) { // your code }

To find the number of days between two dates in salesforce, it provides daysBetween() function which returns the number of days between the Date that is called the method and the specified date.



Your Answer

Interviews

Parent Categories