日付関数 date-functions

日付関数を使用すると、ジャーニー式内で日時の値を操作して作業できます。 これらの関数は、カスタマージャーニーでの時間ベースの条件、スケジュール、時間計算に不可欠です。

日付関数は、次の操作が必要な場合に使用します。

日付関数は、時間ロジックを正確に制御し、特定の期間とスケジュールに応答する、時間依存のジャーニーパスと条件を作成できます。

NOTE
このページの関数は、ジャーニー式で使用できます。 now() などの一部の関数は、メールコンテンツのパーソナライゼーションエディターでは使用できません。 詳細情報

currentTimeInMillis currentTimeInMillis

現在の時刻をエポックミリ秒単位で返します。

構文
currentTimeInMillis()
パラメーター
この関数にパラメーターはありません。
シグネチャと戻り値のタイプ

currentTimeInMillis()

整数を返します。

例

currentTimeInMillis()

「1544712617131」を返します。

dateDiff dateDiff

同じタイプの 2 つの日付または日時の差を返します。 結果の単位はパラメータータイプに応じて異なります。dateOnly パラメーターの場合は​ 日単位 ​の差が返され、dateTimeOnly および dateTime パラメーターの場合は​ ミリ秒単位 ​の差が返されます。 いずれかのパラメーターが null の場合、null を返します。

NOTE
これは、パーソナライゼーションエディターで使用可能な dateDiff とは異なる関数です。 パーソナライズエディターのバージョンでは、dateTime パラメーターのみを受け入れ、常に日単位の差を返します。
構文
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>)

2 つの日付の間の日数を表す整数を返します。

dateDiff(<dateTimeOnly>,<dateTimeOnly>)

2 つの日時の間のミリ秒数を表す整数を返します。

dateDiff(<dateTime>,<dateTime>)

2 つの日時の間のミリ秒数を表す整数を返します。

例

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日(PT)までのミリ秒数を返します。

dateDiff(#{ExperiencePlatform.ProfileFieldGroup.person.birthDate}, toDateOnly('2023-01-01'))

birthDate が dateOnly タイプであると仮定して、プロファイルの birthDate フィールドと 2023年1月1日との間の日数を返します。

inLastDays inLastDays

指定された dateTime が現在の日時とその delta 日前の間にある場合、true を返します。

構文
inLastDays(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inLastDays(<dateTime>,<integer>)

ブール値を返します。

例

inLastDays(toDateTime('2023-12-12T01:11:00Z'), 4)

true を返します。

inLastHours inLastHours

指定された日時が現在の日時とその delta 時間前の間にある場合、true を返します。

構文
inLastHours(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inLastHours(<dateTime>,<integer>)

ブール値を返します。

例

inLastHours(toDateTime('2023-12-12T01:11:00Z'), 4)

true を返します。

inLastHours(@event{MyEvent.timestamp}, 4)

true を返します。

inLastMonths inLastMonths

指定された日付または日時が現在の日時とその delta か月前の間にある場合、true を返します。

構文
inLastMonths(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inLastMonths(<dateTime>,<integer>)

ブール値を返します。

例

inLastMonths(toDateTime('2023-12-12T01:11:00Z'), 4)

true を返します。

inLastYears inLastYears

指定された日付または日時が現在の日時とその delta 年前の間にある場合、true を返します。

構文
inLastYears(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inLastYears(<dateTime>,<integer>)

ブール値を返します。

例

inLastYears(toDateTime('2023-12-12T01:11:00Z'), 4)

true を返します。

inNextDays inNextDays

指定された日付または日時が現在の日時とその delta 日後の間にある場合、true を返します。

構文
inNextDays(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
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
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inNextHours(<dateTime>,<integer>)

ブール値を返します。

例

inNextHours(toDateTime('2023-12-12T01:11:00Z'), 4)

true を返します。

inNextMonths inNextMonths

指定された日付または日時が現在の日時とその delta か月後の間にある場合、true を返します。

構文
inNextMonths(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inNextMonths(<dateTime>,<integer>)

ブール値を返します。

例

inNextMonths(toDateTime('2023-01-12T01:11:00Z'), 4)

true を返します。

inNextYears inNextYears

指定された日付または日時が現在の日時とその delta 年後の間にある場合、true を返します。

構文
inNextYears(<dateTime>,<delta>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
日時 日時
delta 整数
シグネチャと戻り値のタイプ

inNextYears(<dateTime>,<integer>)

ブール値を返します。

例

inNextYears(toDateTime('2021-12-12T01:11:00Z'), 4)

true を返します。

now now

現在の日付を日時形式で返します。 データタイプについて詳しくは、このページを参照してください。

NOTE
この関数は、ジャーニー式でのみ使用できます。 メールのパーソナライゼーションやその他のコンテンツには、代わりに 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

オフセットを含んだ現在の日時を返します。 タイムゾーン ID を指定した場合は、タイムゾーンオフセットが適用されます。 データタイプについて詳しくは、このページを参照してください。

構文
nowWithDelta(<parameters>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2
パラメーター 説明
delta 正または負の整数値
日時の構成要素 「years」、「months」、「days」、「hours」、「minutes」、「seconds」のいずれかを文字列として指定します
タイムゾーン ID タイムゾーン値の文字列表現。 詳しくは、データタイプを参照してください。 タイムゾーン ID は文字列定数である必要があります。 フィールド参照や式は使用できません。
シグネチャと戻り値のタイプ

nowWithDelta(<delta>,<date part>

nowWithDelta(<delta>,<date part>,"<timeZone id>")

日時を返します。

例

nowWithDelta(-2, "hours")

nowWithDelta(-2, "hours", "Europe/Paris")

正確に 2 時間前の日時を返します。

nowWithDelta(1, "months", "Asia/Tokyo")

2026年1月31日(PT)に評価すると 2026-02-28T… を返し、2026年5月31日(PT)に評価すると 2026-06-30T… を返します

nowWithDelta() では、カレンダー月の算術演算を使用します。 ターゲット月の日数が現在の月の日数よりも少ない場合は、その月の最後の有効な日を末日として正規化されます。 関数は翌月にロールオーバーされません。

setHours setHours

日時または日時のみの時を設定します。 例えば、明日の特定の正時まで待つ場合に、その正時を強制的に指定できます。

構文
setHours(<parameter>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2
パラメーター タイプ
日時 日時
タイムゾーンを考慮しない日時 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
パラメーター タイプ
日時 日時
タイムゾーンを考慮しない日時 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:文字列
  • 日時
シグネチャと戻り値のタイプ

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")

「timestamp」フィールドの値が 2021-11-16T16:55:12.939318+01:00 の場合、この関数は 2021-11-17T02:55:12.942115+11:00 を返します。

AI Knowledge Reference

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 now or nowWithDelta
  • 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 setHours or setDays
  • 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 nowWithDelta to 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 use getCurrentZonedDateTime() instead
  • The timezone ID in nowWithDelta must be a string constant — field references and dynamic expressions are not supported
  • The timezone ID in updateTimeZone must be a string constant
  • dateDiff requires both parameters to be the same data type (dateOnly, dateTimeOnly, or dateTime); mixing types is not supported
  • dateDiff returns null if either parameter is null
  • dateDiff returns days for dateOnly parameters, but milliseconds (not days) for dateTimeOnly and dateTime parameters — 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 (accepts dateOnly, dateTimeOnly, or dateTime; returns days or milliseconds depending on type) ≠ the personalization editor’s dateDiff (accepts only dateTime; always returns days)

FAQ:

  • Q: Can I use now() in email personalization content? — No, now() is only available in journey expressions. Use getCurrentZonedDateTime() 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 updateTimeZone do differently from setHours? — updateTimeZone keeps the same instant in time but expresses it in a different timezone, while setHours actually changes the hour component of the datetime value.
  • Q: Can the timezone parameter in nowWithDelta be 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).
recommendation-more-help
journey-optimizer-help