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.

Access Date Functions with Time Zone Enabled

Use these functions to get the day, week, year, and other parts of DateTime or DateOnly fields. The return values are numbers.

To enable Time Zone for your org, follow the directions in Enable Custom Time Zones.

For the allowed formats, see Date Formats.

  • year (DateTime | DateOnly)
  • quarter (DateTime | DateOnly)
  • month (DateTime | DateOnly)
  • week (DateTime | DateOnly)
  • day (DateTime | DateOnly)
  • hour (DateTime)
  • minute (DateTime)
  • second (DateTime)
  • fiscalYear (DateTime | DateOnly)
  • fiscalQuarter (DateTime | DateOnly)
  • fiscalMonth (DateTime | DateOnly)
  • fiscalWeek (DateTime | DateOnly)
  • epochDay (DateTime | DateOnly)
  • epochSecond( DateTime | DateOnly)

Examples

Use year(), month(), and day() to project the year, month, and day for each record. CloseDate can be a DateTime or DateOnly type.
1q = foreach q generate year('CloseDate') as "Year", month('CloseDate') as "Month", day('CloseDate') as "Day";

Use month() to find results that closed in December.

1q = filter q by month('CloseDate') == 12;

Use month() to order opportunities by month of close date.

1q = order q by month('CloseDate');

For even more granularity, add hour(), minute(), and second() to project the time for each record. These functions can only be used with a DateTime type.

1q = foreach q generate year('CloseDate') as "Year", month('CloseDate') as "Month", day('CloseDate') as "Day", 
2          hour('CloseDate') as "Hour", minute('CloseDate') as "Minute", second('CloseDate') as "Second";

Use hour() to order opportunities by hour of close date.

1q = order q by hour('CloseDate');