Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

daysBetween()

Returns the number of days between two dates. This function is only valid in a foreach statement.

Syntax

daysBetween(date1, date2)

date1 specifies the start date.

date2 specifies the end date.

Usage

If date1 is after date2, the number of days returned is a negative number.

You must use daysBetween() in a foreach() statement. You cannot use this function in group by, order by, or filter statements.

Example

How many days did it take to close each opportunity? Use daysBetween().

1q = load "DTC_Opportunity";
2q = foreach q generate daysBetween(toDate(CreatedDate_sec_epoch), toDate(CloseDate_sec_epoch) ) as 'Days to Close';
3q = order q by 'Days to Close';

Example

How long has each opportunity been open for, in days? Use daysBetween() and now().

1q = load "DTC_Opportunity";
2q = filter q by 'Closed' == "false";
3q = foreach q generate daysBetween(toDate(CreatedDate_sec_epoch), now() ) as 'Days to Close';
4q = order q by 'Days to Close';