日付関数 date-functions
日付関数を使用すると、ジャーニー式内で日時の値を操作して作業できます。 これらの関数は、カスタマージャーニーでの時間ベースの条件、スケジュール、時間計算に不可欠です。
日付関数は、次の操作が必要な場合に使用します。
- 特定のタイムゾーン処理(now、nowWithDelta、currentTimeInMillis)を使用して現在の時刻または日付を取得
- パラメーターの種類(dateDiff)に応じて、2つの日付または日時の差を数日またはミリ秒単位で計算します
- 日付が特定の時間範囲(inLastDays、inLastHours、inLastMonths、inLastYears、inNextDays、inNextHours、inNextMonths、inNextYears)に該当するかどうかを確認
- 日時コンポーネント(setHours、setDays、updateTimeZone)を変更
- 時間ベースの計算と比較を実行
- 異なる時間形式と表示域間を変換
日付関数は、時間ロジックを正確に制御し、特定の期間とスケジュールに応答する、時間依存のジャーニーパスと条件を作成できます。
now() などの一部の関数は、メールコンテンツのパーソナライゼーションエディターでは使用できません。 詳細情報currentTimeInMillis currentTimeInMillis
現在の時刻をエポックミリ秒単位で返します。
currentTimeInMillis()currentTimeInMillis()
整数を返します。
currentTimeInMillis()
「1544712617131」を返します。
dateDiff dateDiff
同じタイプの2つの日付または日時の差分を返します。 結果の単位はパラメーターの種類によって異なります:dateOnly パラメーターは 日 で差を返し、dateTimeOnly パラメーターとdateTime パラメーターは ミリ秒 で差を返します。 いずれかのパラメーターがnullの場合、nullを返します。
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日までのミリ秒数を返します。
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
現在の日付を日時形式で返します。 データタイプについて詳しくは、このページを参照してください。
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 を返します。
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).