Returns the time (as the number of milliseconds from the epoch date) from a datetime field. The time function is also used to convert a given datetime field into the specified time period. The function supports relative dates. The time function operates on the UTC time zone.
- hour: converts the given time to the hour of the day.
For example, for time(now,"hour"), if now is 1:30 p.m., this resolves to today's date at 1 p.m.
- day: converts the given time to the day of the month.
For example, for time(now,"day"), if now is the 5th day of the month, this resolves to today's date at zero hour (12:00 a.m.).
- week: converts the given time to the week of the year.
For example, time(now,"week") resolves to a datetime that represents the week of the year at zero hour (12:00 a.m.).
- month: converts the given time to the month of the year.
For example, time(now,"month") resolves to a datetime that represents the month of the year at zero hour (12:00 a.m.).
- quarter: converts the given time to the month of the year representing the
start of the quarter.
For example, for time(now,"quarter"), if now is 12/31/2012, this resolves to 10/01/2012 at zero hour (12:00 a.m.).
- year: converts the given time to calendar year.
For example, for time(now,"year"), if now is 12/31/2012, this resolves to 01/01/2012 at zero hour (12:00 a.m.).
Example 1:
As shown in the following example, you can pass the result of parseDate to the time function.
now - time( parseDate( get("Customer.demographics.dob") ) ) < 1000 * 60 * 60 * 24 * 30
Example 2:
The following expression evaluates to true if today is May 2015 regardless of the day and time.
time(now,"month") == time("2015-05-11T08:20:00.000Z","month")
Example 3:
The time function also supports relative dates and time periods. For example, time(now,5,"day","past") calculates the time 5 days in the past from the given time. If now is 11/24/2014, this returns 11/19/2014 at zero hour (12:00 a.m.). For another example, time(now,12,"hour","future") calculates the time 12 hours in the future. If now is 9 a.m., this returns 9 p.m.
The following expression evaluates to true if the expiration date occurs before 3 months from now.
time(get("Account.dates.expiration ")) < time(now,3,"month","future")