function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mitchell MendoncaMitchell Mendonca 

Trigger to calculate dates

Hi,

I'm looking for help with setting up a trigger to calculate the number of days from a start date to an end date...
I'm new to this stuff so any help would be appreciated.

Thanks,

Mitchell
Shashikant SharmaShashikant Sharma
You could use DaysBetween method to get number of days between

daysBetween(secondDate)Returns the number of days between the Date that called the method and the specified date.Signature

public Integer daysBetween(Date secondDate)

Parameters

secondDate
Type: Date

Return Value

Type: Integer

Usage

If the Date that calls the method occurs after the compDate, the return value is negative.


Example: 
Date startDate = Date.newInstance(2008, 1, 1);
Date dueDate = Date.newInstance(2008, 1, 30);
Integer numberDaysDue = startDate.daysBetween(dueDate);

 
Kunal01Kunal01
Hi Mitchell,

You can use date methods to calculate no of days between to days. 

Date startDate = Date.newInstance(2008, 1, 1);

Date dueDate = Date.newInstance(2008, 1, 30);

Integer numberDaysDue = startDate.daysBetween(dueDate);

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_date.htm#apex_System_Date_daysBetween

Please mark this closed if this solves your purpose.

Thanks,
Kunal