日期函式 date-functions
日期函式可讓您在歷程運算式中控制和使用日期和時間值。 這些功能對於客戶歷程中以時間為基礎的條件、排程和時間計算至關重要。
有以下需求時,請使用日期函式:
- 取得目前時間或具有特定時區處理的日期(now,nowWithDelta,currentTimeInMillis)
- 根據引數型別(dateDiff),計算兩個日期或日期時間之間的差異(以天或毫秒為單位)
- 檢查日期是否落在特定時間範圍內(inLastDays,inLastHours,inLastMonths,inLastYears,inNextDays,inNextHours,inNextMonths,inNextYears)
- 修改日期和時間元件(setHours, setDays, updateTimeZone)
- 執行以時間為基礎的計算和比較
- 在不同時間格式和表示之間轉換
日期函式可精確控制暫時邏輯,讓您建立對時間敏感的歷程路徑和條件,以回應特定時間範圍和排程。
now()等某些函式。 了解更多currentTimeInMillis currentTimeInMillis
傳回目前時間(以Epoch毫秒為單位)。
currentTimeInMillis()currentTimeInMillis()
傳回整數。
currentTimeInMillis()
傳回「1544712617131」。
dateDiff dateDiff
傳回相同型別的兩個日期或日期時間之間的差異。 結果的單位取決於引數型別: dateOnly引數傳回 天 的差異,而dateTimeOnly和dateTime引數傳回 毫秒 的差異。 如果任一引數為null,則傳回null。
dateDiff(<date1>,<date2>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期1 | dateOnly、dateTimeOnly或dateTime |
| 日期2 | dateOnly、dateTimeOnly或dateTime |
兩個引數必須使用相同的資料型別;不支援混合型別(例如dateOnly搭配dateTime)。 引數可以是常值日期值、其他函式(例如now())或內容屬性(事件裝載欄位、自訂動作回應欄位、設定檔或實體欄位以及變數),只要它們是dateOnly、dateTimeOnly或dateTime型別即可。
dateDiff(<dateOnly>,<dateOnly>)
傳回整數,代表兩個日期之間的天數。
dateDiff(<dateTimeOnly>,<dateTimeOnly>)
傳回代表兩個日期時間之間的毫秒數的整數。
dateDiff(<dateTime>,<dateTime>)
傳回代表兩個日期時間之間的毫秒數的整數。
dateDiff(toDateOnly('2023-12-15'), toDateOnly('2023-12-12'))
傳回3 (天)。
dateDiff(toDateTimeOnly('2023-12-15T00:00:00'), toDateTimeOnly('2023-12-12T00:00:00'))
傳回259200000 (毫秒,等於3天)。
dateDiff(now(), toDateTime('2024-12-25T00:00:00Z'))
傳回今天和2024年12月25日之間的毫秒數。
dateDiff(#{ExperiencePlatform.ProfileFieldGroup.person.birthDate}, toDateOnly('2023-01-01'))
傳回設定檔的birthDate欄位與2023年1月1日之間的天數,假設birthDate是輸入為dateOnly。
inLastDays inLastDays
如果指定的dateTime介於現在與現在 — 差異天數之間,則傳回true。
inLastDays(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inLastDays(<dateTime>,<integer>)
傳回布林值。
inLastDays(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回true。
inLastHours inLastHours
如果指定的日期時間介於現在和現在之間 — 差異小時,則傳回true。
inLastHours(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inLastHours(<dateTime>,<integer>)
傳回布林值。
inLastHours(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回true。
inLastHours(@event{MyEvent.timestamp}, 4)
傳回true。
inLastMonths inLastMonths
如果指定的日期或dateTime介於現在和現在 — 差異月份之間,則傳回true。
inLastMonths(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inLastMonths(<dateTime>,<integer>)
傳回布林值。
inLastMonths(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回true。
inLastYears inLastYears
如果指定的日期或dateTime介於現在和現在之間 — 差異年份,則傳回true。
inLastYears(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inLastYears(<dateTime>,<integer>)
傳回布林值。
inLastYears(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回true。
inNextDays inNextDays
如果指定的日期或日期時間介於現在和現在+差異天數之間,則傳回true。
inNextDays(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inNextDays(<dateTime>,<integer>)
傳回布林值。
inNextDays(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回true。
inNextHours inNextHours
如果指定的日期或日期時間介於現在和現在+差異小時之間,則傳回true。
inNextHours(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inNextHours(<dateTime>,<integer>)
傳回布林值。
inNextHours(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回true。
inNextMonths inNextMonths
如果指定的日期或dateTime介於現在和現在+差異月份之間,則傳回true。
inNextMonths(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inNextMonths(<dateTime>,<integer>)
傳回布林值。
inNextMonths(toDateTime('2023-01-12T01:11:00Z'), 4)
傳回true。
inNextYears inNextYears
如果指定的日期或dateTime介於現在和現在+差異年度之間,則傳回true。
inNextYears(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| delta | 整數 |
inNextYears(<dateTime>,<integer>)
傳回布林值。
inNextYears(toDateTime('2021-12-12T01:11:00Z'), 4)
傳回true。
now now
以日期時間格式傳回目前日期。 如需資料型別的詳細資訊,請參閱此頁面。
getCurrentZonedDateTime()。 了解更多now(<parameter>)| table 0-row-2 1-row-2 | |
|---|---|
| 參數 | 說明 |
| 字串 | 時區識別碼(選擇性) |
now()
now("<timeZone id>")
傳回日期時間。
now()
傳回2023-06-03T06:30Z。
toString(now())
傳回「2023-06-03T06:30Z」
now("Europe/Paris")
傳回2023-06-03T08:30+02:00。
nowWithDelta nowWithDelta
傳回包含位移的目前日期時間。 如果指定了時區識別碼,則會套用時區位移。 如需資料型別的詳細資訊,請參閱此頁面。
nowWithDelta(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| 參數 | 說明 |
| delta | 正或負整數值 |
| 日期部分 | 年、月、日、小時、分鐘或秒做為字串 |
| 時區id | 時區值的字串表示法。 如需詳細資訊,請參閱資料型別。 時區ID必須是字串常數。 它不能是欄位參考或運算式。 |
nowWithDelta(<delta>,<date part>
nowWithDelta(<delta>,<date part>,"<timeZone id>")
傳回日期時間。
nowWithDelta(-2, "hours")
nowWithDelta(-2, "hours", "Europe/Paris")
傳回2小時前的dateTime。
nowWithDelta(1, "months", "Asia/Tokyo")
在2026-01-31評估時,傳回2026-02-28T…;在2026-05-31評估時,傳回2026-06-30T…
nowWithDelta()使用行事曆月算術。 如果目標月份的天數少於當月當月,則結果會標準化為該月的最後一個有效日。 函式不會捲動至下個月。
setHours setHours
僅設定日期時間或日期時間的小時。 例如,如果您要等到明天的特定小時,則可以強制該小時。
setHours(<parameter>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| 不考慮時區的日期時間 | dateTimeOnly |
| 小時 | 整數 |
setHours(<dateTime>,<hours>)
傳回日期時間。
setHours(<dateTimeOnly>,<hours>)
傳回日期時間,不考慮時區。
setHours(toDateTime('2023-12-12T01:11:00Z'), 4)
傳回2023-12-12T04:11:00Z。
setHours(nowWithDelta(1, "days"), 20)
傳回明天晚上8:XY,XY是目前時間評估的分鐘數。 如果評估在凌晨2:45進行,則傳回時間將會是晚上8:45。
setDays setDays
僅設定日期時間或日期時間的日期。 例如,如果您要等到月份的某一天,則可以強制該天。
setDays(<parameter>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| 參數 | 類型 |
| 日期時間 | dateTime |
| 不考慮時區的日期時間 | dateTimeOnly |
| 天 | 整數 |
setDays(<dateTime>,<days>)
傳回日期時間。
setDays(<dateTimeOnly>,<days>)
傳回日期時間,不考慮時區。
setDays(toDateTime('2023-12-12T01:11:00Z'), 25)
傳回2023-12-25T01:11:00Z。
setDays(toDateTimeOnly(@event{MyEvent.registrationDate}), 1)
updateTimeZone updateTimeZone
傳回新的日期時間,而在同一時間傳回新的時區。
updateTimeZone(<parameters>)- 時區id:字串
- dateTime
updateTimeZone(<dateTime>,<timeZone id>)
傳回日期時間。
updateTimeZone( toDateTime("2023-08-28T08:15:30.123-07:00"), "Europe/Paris"))
傳回2023-08-28T17:15:30.123+02:00。
updateTimeZone(@event{MyExpEvent.timestamp}, "Australia/Sydney")
如果時間戳記欄位的值為2021-11-16T16:55:12.939318+01:00,則函式會傳回2021-11-17T02:55:12.942115+11:00。
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents all date and time functions available in AJO journey expressions, covering how to get the current time, check whether a date falls within a relative time window, and modify date/time components.
Intents:
- Get the current datetime (with optional timezone) using
nowornowWithDelta - Retrieve the current time as an epoch integer using
currentTimeInMillis - Calculate the difference between two dates or date-times using
dateDiff - Check if a datetime falls within the last N days, hours, months, or years using
inLastDays,inLastHours,inLastMonths,inLastYears - Check if a datetime falls within the next N days, hours, months, or years using
inNextDays,inNextHours,inNextMonths,inNextYears - Force a specific hour or day of the month on a datetime value using
setHoursorsetDays - Convert a datetime to a different timezone while preserving the same instant using
updateTimeZone
Glossary:
- dateOnly: A date value with no time or timezone information (product-specific)
- dateTime: A date-time value that includes timezone offset information (product-specific)
- dateTimeOnly: A date-time value with no timezone information (product-specific)
- epoch milliseconds: An integer representing the number of milliseconds elapsed since 1970-01-01T00:00:00Z
- delta: An integer offset (positive or negative) used with
nowWithDeltato shift the current time by a number of years, months, days, hours, minutes, or seconds
Guardrails:
now()is only available in journey expressions; for email personalization usegetCurrentZonedDateTime()instead- The timezone ID in
nowWithDeltamust be a string constant — field references and dynamic expressions are not supported - The timezone ID in
updateTimeZonemust be a string constant dateDiffrequires both parameters to be the same data type (dateOnly,dateTimeOnly, ordateTime); mixing types is not supporteddateDiffreturnsnullif either parameter isnulldateDiffreturns days fordateOnlyparameters, but milliseconds (not days) fordateTimeOnlyanddateTimeparameters — convert accordingly when comparing results across types
Terminology:
- Canonical name: Date functions — Acronym: none — variants: date-time functions, temporal functions
- Synonyms: “now()” = “current datetime”; “currentTimeInMillis()” = “current epoch milliseconds”
- Do not confuse: “inLastDays” (looks back in time) ≠ “inNextDays” (looks forward in time)
- Do not confuse: “setHours” (replaces the hour component) ≠ “nowWithDelta” (offsets the current time)
- Do not confuse: “updateTimeZone” (same instant, different timezone representation) ≠ “setHours” (changes the time value itself)
- Do not confuse: the journey expression editor’s
dateDiff(acceptsdateOnly,dateTimeOnly, ordateTime; returns days or milliseconds depending on type) ≠ the personalization editor’sdateDiff(accepts onlydateTime; always returns days)
FAQ:
- Q: Can I use
now()in email personalization content? — No,now()is only available in journey expressions. UsegetCurrentZonedDateTime()for email personalization. - Q: How do I check if an event happened in the last 24 hours? — Use
inLastHours(@event{MyEvent.timestamp}, 24). - Q: How do I get the current time offset by 2 hours in the past? — Use
nowWithDelta(-2, "hours"). - Q: What does
updateTimeZonedo differently fromsetHours? —updateTimeZonekeeps the same instant in time but expresses it in a different timezone, whilesetHoursactually changes the hour component of the datetime value. - Q: Can the timezone parameter in
nowWithDeltabe a profile field? — No, the timezone ID must be a string constant; field references are not supported. - Q: What happens when
nowWithDelta()is used with months and the current date is a month-end date? — The function uses calendar-month arithmetic and normalizes the result to the last valid day of the target month. For example, adding 1 month to January 31 returns February 28 (not March 3).