日付関数 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

両方のパラメーターで同じデータ型を使用する必要があります。型(dateOnlydateTimeなど)の混在はサポートされていません。 パラメーターには、リテラル日付値、now()などの他の関数、コンテキスト属性(イベントペイロードフィールド、カスタムアクション応答フィールド、プロファイルまたはエンティティのフィールド、変数)を、dateOnlydateTimeOnly、または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日までのミリ秒数を返します。

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

birthDatedateOnlyと入力されたと仮定して、プロファイルの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-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
パラメーター タイプ
日時 日時
タイムゾーンを考慮しない日時 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