日期函数 date-functions
通过日期函数,您可以在历程表达式中处理并使用日期和时间值。 这些函数对于客户历程中基于时间的条件、计划和时间计算至关重要。
当您需要以下任务时,请使用日期函数:
- 获取具有特定时区处理的当前时间或日期(now,nowWithDelta,currentTimeInMillis)
- 根据参数类型(dateDiff),计算两个日期或日期时间之间的差异(以天或毫秒为单位)
- 检查日期是否在特定时间范围内(inLastDays,inLastHours,inLastMonths,inLastYears,inNextDays,inNextHours,inNextMonths,inNextYears)
- 修改日期和时间组件(setHours,setDays,updateTimeZone)
- 执行基于时间的计算和比较
- 在不同时间格式和表示法之间转换
日期函数提供了对时间逻辑的精确控制,允许您创建对时间敏感的历程路径和条件,以响应特定时间范围和计划。
now())在电子邮件内容的个性化编辑器中不可用。 了解详情currentTimeInMillis currentTimeInMillis
返回当前时间(以纪元毫秒为单位)。
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 |
| 增量 | 整数 |
inLastDays(<dateTime>,<integer>)
返回布尔值。
inLastDays(toDateTime('2023-12-12T01:11:00Z'), 4)
返回真。
inLastHours inLastHours
如果给定的日期时间介于现在和现在之间 — 增量小时,则返回true。
inLastHours(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inLastHours(<dateTime>,<integer>)
返回布尔值。
inLastHours(toDateTime('2023-12-12T01:11:00Z'), 4)
返回真。
inLastHours(@event{MyEvent.timestamp}, 4)
返回真。
inLastMonths inLastMonths
如果给定的日期或日期时间介于现在和现在之间 — 增量月份,则返回true。
inLastMonths(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inLastMonths(<dateTime>,<integer>)
返回布尔值。
inLastMonths(toDateTime('2023-12-12T01:11:00Z'), 4)
返回真。
inLastYears inLastYears
如果给定的日期或日期时间介于现在和现在之间 — 增量年,则返回true。
inLastYears(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inLastYears(<dateTime>,<integer>)
返回布尔值。
inLastYears(toDateTime('2023-12-12T01:11:00Z'), 4)
返回真。
inNextDays inNextDays
如果给定的日期或日期时间介于现在和现在+增量天之间,则返回true。
inNextDays(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inNextDays(<dateTime>,<integer>)
返回布尔值。
inNextDays(toDateTime('2023-12-12T01:11:00Z'), 4)
返回真。
inNextHours inNextHours
如果给定的日期或日期时间介于现在和现在+增量小时数之间,则返回true。
inNextHours(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inNextHours(<dateTime>,<integer>)
返回布尔值。
inNextHours(toDateTime('2023-12-12T01:11:00Z'), 4)
返回真。
inNextMonths inNextMonths
如果给定的日期或日期时间介于现在和现在+增量月份之间,则返回true。
inNextMonths(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inNextMonths(<dateTime>,<integer>)
返回布尔值。
inNextMonths(toDateTime('2023-01-12T01:11:00Z'), 4)
返回真。
inNextYears inNextYears
如果给定的日期或日期时间介于现在和现在+增量年之间,则返回true。
inNextYears(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| 参数 | 类型 |
| 日期时间 | dateTime |
| 增量 | 整数 |
inNextYears(<dateTime>,<integer>)
返回布尔值。
inNextYears(toDateTime('2021-12-12T01:11:00Z'), 4)
返回真。
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 | |
|---|---|
| 参数 | 说明 |
| 增量 | 正或负整数值 |
| 日期部分 | 年、月、日、小时、分钟或秒 |
| 时区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).