コンバージョン関数 conversion-functions

コンバージョン関数を使用すると、ジャーニー式内でデータをあるタイプから別のタイプに変換できます。 これらの関数は、様々なデータソースや操作で作業する際に、データの互換性と適切なタイプの処理を確保するために不可欠です。

コンバージョン関数は、次の操作が必要な場合に使用します。

  • 文字列値を数値、ブール値、日付タイプに変換(toIntegertoDecimaltoBool
  • 日付と時刻を異なる形式と表示域の間で変換(toDateTimetoDateTimeOnlytoDateOnly
  • 数値を整数タイプと小数タイプの間でキャスト(toIntegertoDecimal
  • 値を文字列形式(toString)または期間(toDuration)に変換
  • 比較や演算のタイプの互換性を確保
  • 異なるタイプ形式を持つ場合がある外部ソースからのデータを処理

各コンバージョン関数は、タイプ固有のルールとエッジケースを自動的に処理するので、ジャーニー式でのデータ変換の信頼性と予測可能性が向上します。

クイックリファレンス quick-reference

目標
関数
文字列またはエポックを​ のタイムゾーンを持つ ​日付に変換
toDateTime
文字列または日付を​ タイムゾーンのない ​日時に変換します
toDateTimeOnly
日付のみを抽出(年 – 月 – 日、時間なし)
toDateOnly
整数に変換
toInteger
10進数に変換
toDecimal
true/falseに変換
toBool
任意の値を文字列に変換
toString
デュレーションに変換(ISO-8601、PT10Hなど)
toDuration
TIP
toDateTime vs. toDateTimeOnly: タイムゾーンが重要な場合(例:メッセージのスケジュール設定、地域間のイベントタイムスタンプの比較)にtoDateTimeを使用します。 ローカルの日時のみが関連し、タイムゾーンを無視できる場合(条件でカレンダーの日付を比較する場合など)は、toDateTimeOnlyを使用します。

よくある落とし穴 pitfalls

  • タイムゾーンは文字列定数​である必要があります。toDateTimeのタイムゾーン引数は、フィールド参照または動的式にすることはできません。 "UTC""Europe/Paris"などのリテラル文字列を常に渡します。
  • 文字列の入力に必要な​ISO-8601形式 – 文字列をtoDateTimeまたはtoDateTimeOnlyに渡す場合は、ISO-8601形式(例:"2023-08-18T23:17:59.123Z")に従っていることを確認してください。 形式が正しくない文字列は、エラーなしでnullを返します。
  • エポック値はミリ秒ですtoDateTime(1560762190189)はミリ秒を想定しています。 ソースがUnix タイムスタンプを秒単位で提供する場合は、最初に1000を掛けます(例:toDateTime(myField * 1000))。
  • toBool with unexpected stringstoBoolは、文字列値が正確に"true"の場合にのみtrueを返します。 その他の文字列("1""yes""TRUE"を含む)はfalseを返します。

toBool toBool

引数の値をタイプに応じてブール値に変換します。

  • 文字列から変換する場合:文字列値をブール値として変換します。文字列値が「true」の場合は true、それ以外の場合は false を返します。
  • 数値から変換する場合:数値が 0 に等しくない場合は true 、それ以外の場合は false を返します。
構文
toBool(<parameter>)
パラメーター
  • 小数
  • ブール値
  • 文字列
  • 整数
シグネチャと戻り値のタイプ

toBool(<decimal>)

toBool(<boolean>)

toBool(<string>)

toBool(<integer>)

ブール値を返します。

toBool("true")

toBool(1)

true を返します。

toBool("this is not a boolean")

false を返します。

toDateOnly toDateOnly

引数を dateOnly 型の値に変換します。 データタイプについて詳しくは、このを参照してください。

構文
toDateOnly(<parameters>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2
パラメーター タイプ
「YYYY-MM-DD」(XDM 形式)としての日付の文字列表現。 ISO-8601 形式もサポートしています。full-date の部分に限り考慮されます(RFC 3339、セクション 5.6 文字列
日時 日時
タイムゾーンを含まない日時 dateTimeOnly
エポックのミリ秒単位の整数値 整数
シグネチャと戻り値のタイプ

toDateOnly(<dateTime>)

toDateOnly(<dateTimeOnly>)

toDateOnly(<string>)

toDateOnly(<integer>, <integer>, <integer>)

dateOnly 型の値を返します。

toDateOnly("2023-08-18")

toDateOnly("2023-08-18T00:00:00.000Z")

toDateOnly("2023-08-18T00:00:00")

すべて、2023/08/18 を表す dateOnly オブジェクトを返します。

toDateOnly(#{ExperiencePlatform.ProfileFieldGroup.person.birthDate})

dateOnly を返します。

toDateTime toDateTime

パラメーターをタイプに応じて日時値に変換します。

構文
toDateTime(<parameters>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2
パラメーター 説明
文字列 ISO-8601 形式の日時。 タイムゾーン情報を含む日時の文字列表現
文字列 タイムゾーン ID。 タイムゾーン識別子(例:「UTC」、「ヨーロッパ/パリ」)
dateOnly タイムゾーンを含まずに日付を表し、年-月-日として表示されます
dateTimeOnly タイムゾーンのない日時を表し、年-月-日-時間-分-秒-ミリ秒と表示されます
整数 エポックのミリ秒単位の整数値
シグネチャと戻り値のタイプ

toDateTime(<string>)

toDateTime(<string>, <dateOnly>)

toDateTime(<string>, <dateTimeOnly>)

toDateTime(<integer>)

dateTime を返します。

toDateTime("2023-08-18T23:17:59.123Z")

2023-08-18T23:17:59.123Z を返します

ISO-8601 文字列には、既にタイムゾーン情報が含まれています。

toDateTime("Europe/Paris", toDateOnly("2023-08-18"))

2023-08-18T00:00:00.000+02:00を返します

タイムゾーンと日付のみの値を組み合わせて日時を作成します。 時間は、指定されたタイムゾーンの午前 0 時(00:00:00)に設定されます。

toDateTime("UTC", toDateTimeOnly("2023-08-18T23:17:59.123"))

2023-08-18T23:17:59.123Z を返します

(タイムゾーン情報を持たない)dateTimeOnly 値にタイムゾーンを適用して日時を作成します。

toDateTime(1560762190189)

2019-06-17T09:03:10.189Z を返します。

Unix タイムスタンプをミリ秒単位で dateTime 値に変換します。

NOTE
タイムゾーン ID は文字列定数である必要があります。 フィールド参照や式は使用できません。 データタイプについて詳しくは、このページを参照してください。

toDateTimeOnly toDateTimeOnly

引数値を日時のみの値に変換します。

構文
toDateTimeOnly(<parameters>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター タイプ
ISO-8601 形式つまり「YYYY-MM-DD」形式(XDM 日付形式)の日時 文字列
日時 日時
シグネチャと戻り値のタイプ

toDateTimeOnly(<dateTime>)

toDateTimeOnly(<string>)

タイムゾーンを無視して日時を返します。

toDateTimeOnly ("2023-08-18")

2023-08-18T00:00:00.000 を表す日時を返します

toDateTimeOnly(now())

toDecimal toDecimal

引数の値をタイプに応じて小数値に変換します。

構文
toDecimal(<parameter>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2
パラメーター 説明
文字列 文字列値を小数に変換します
日時 日付をミリ秒数(エポックミリ秒)に変換します
ブール値 ブール値を true の場合は 1 に、false の場合は 0 に変換します
整数 10進数に変換します(例:1は1.0になります)。
シグネチャと戻り値のタイプ

toDecimal(<integer>)

toDecimal(<decimal>)

toDecimal(<string>)

toDecimal(<boolean>)

小数を返します。

toDecimal("4.0")

4.0 を返します。

toDuration toDuration

引数の値を期間に変換します。 データタイプについて詳しくは、このページを参照してください。

構文
toDuration(<parameter>)
パラメーター
table 0-row-2 1-row-2 2-row-2
パラメーター 説明
文字列 ISO-8601 の期間形式 PnDTnHnMn.nS に基づく形式(日数は正確に 24 時間と見なされます)
整数 ミリ秒数

文字列式の場合:指定できる形式は、ISO-8601 期間形式 PnDTnHnMn.nS に基づいたもので、1 日は正確に 24 時間と見なされます。

文字列は、ASCII の負または正の記号で表されるオプションの符号で始まります。 負の場合は、期間全体が負の値になります。 ASCII 文字「P」が次に現れ、大文字または小文字で表されます。 その後に 4 つのセクションがあり、それぞれが数値とサフィックスで構成されます。 各セクションには、日、時間、分および秒を示す「D」、「H」、「M」および「S」の ASCII サフィックスがあります(大文字でも小文字でもかまいません)。 サフィックスは、順序に従って現れる必要があります。 ASCII 文字「T」は、時、分、秒のセクションの最初の出現箇所(存在する場合)より前に記述する必要があります。 4 つのセクションのうち少なくとも 1 つが存在し、「T」が存在する場合は、「T」の後に少なくとも 1 つのセクションが存在する必要があります。 各セクションの数値部分は、1 つ以上の ASCII 数字で構成される必要があります。 数字の接頭辞は、ASCII の負または正の符号を付けてもかまいません。 日数、時間数および分数は long 型の値に解析される必要があります。 秒数は long 型の値(オプションで小数を含む)に解析される必要があります。 小数点はドットまたはコンマです。 小数部は 0~9 桁まで可能です。

シグネチャと戻り値のタイプ

toDuration(<string>)

toDuration(<integer>)

期間を返します。

toDuration("PT10H")

10 時間の期間を返します。

toDuration("PT4S")

4 秒の期間を返します。

toDuration(4000)

4 秒の期間を返します。

toInteger toInteger

引数の値を整数に変換します。

構文
toInteger(<parameter>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2
パラメーター 説明
文字列 文字列値を整数に変換します
日時 日付をミリ秒数(エポックミリ秒)に変換します
小数 小数部を削除して整数に変換します(例:1.5 は 1 になります)
ブール値 ブール値を true の場合は 1 に、false の場合は 0 に変換します
シグネチャと戻り値のタイプ

toInteger(<dateTime>)

toInteger(<decimal>)

toInteger(<integer>)

toInteger(<string>)

toInteger(<boolean>)

整数を返します。

toInteger("4")

4 を返します。

toString toString

引数の値を、タイプに応じて文字列値に変換します。 データタイプについて詳しくは、このページを参照してください。

構文
toString(<parameter>)
パラメーター
table 0-row-2 1-row-2 2-row-2 3-row-2 4-row-2 5-row-2 6-row-2
パラメーター 説明
日時 日付を UTC 日付フォーマットに変換します
日時のみ 日付を UTC 日付フォーマットに変換します
期間 対応するミリ秒数の文字列に変換します
整数 値の文字列表現に変換します(1 は “1” になります)
小数 値の文字列表現に変換します(1.5 は “1.5” になります)
ブール値 ブール値を true の場合は「true」、false の場合は「false」に変換します
シグネチャと戻り値のタイプ

toString(<dateTimeOnly>)

toString(<dateTime>)

toString(<duration>)

toString(<boolean>)

toString(<integer>)

toString(<decimal>)

文字列を返します。

toString(4)

「4」を返します。

toString(#{ExperiencePlatform.test_date.person.birthDate}))

例えば「2023/08/18」のように、指定された dateOnly フィールド(XDM 日付フィールド)の文字列表現を返します。

toString(toDuration(1520))

「PT1.52S」を返します。

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 conversion functions in AJO journey expressions, explaining how to transform values between types such as string, integer, decimal, boolean, date, datetime, and duration.

Intents:

  • Convert a string or epoch integer to a timezone-aware datetime using toDateTime
  • Convert a string or datetime to a timezone-less datetime using toDateTimeOnly
  • Extract a date-only value (year-month-day) from a string or datetime using toDateOnly
  • Cast a value to an integer, decimal, or boolean using toInteger, toDecimal, or toBool
  • Serialize any value to its string representation using toString
  • Convert a string or millisecond integer to a duration using toDuration

Glossary:

  • dateTime: A datetime value that includes timezone offset information (product-specific)
  • dateTimeOnly: A datetime value with no timezone information (product-specific)
  • dateOnly: A date value representing year-month-day with no time component (product-specific)
  • duration: A time period expressed in ISO-8601 format (e.g., PT10H) (product-specific)
  • epoch milliseconds: Unix timestamp expressed in milliseconds since 1970-01-01T00:00:00Z

Guardrails:

  • The timezone argument in toDateTime must be a string constant — field references and dynamic expressions are not allowed
  • String inputs to toDateTime and toDateTimeOnly must follow ISO-8601 format; malformed strings return null without an error
  • toDateTime with an epoch integer expects milliseconds; multiply seconds-based timestamps by 1000 before passing
  • toBool returns true only for the exact string "true"; strings like "1", "yes", or "TRUE" return false

Terminology:

  • Canonical name: Conversion functions — Acronym: none — variants: type casting functions, type conversion functions
  • Synonyms: “toDateTime” = “convert to datetime with timezone”; “toDateTimeOnly” = “convert to datetime without timezone”
  • Do not confuse: “toDateTime” (timezone-aware) ≠ “toDateTimeOnly” (no timezone)
  • Do not confuse: “toDateOnly” (date only, no time) ≠ “toDateTime” (date and time with timezone)

FAQ:

  • Q: When should I use toDateTime versus toDateTimeOnly? — Use toDateTime when timezone information matters (e.g., scheduling or cross-region comparisons); use toDateTimeOnly when only the local date-time is relevant and timezone can be ignored.
  • Q: Why does toBool("TRUE") return false?toBool only recognizes the exact lowercase string "true"; all other string values including "TRUE" or "yes" return false.
  • Q: How do I convert a Unix timestamp in seconds to a dateTime? — Multiply the seconds value by 1000 to get milliseconds, then pass it to toDateTime, e.g., toDateTime(myField * 1000).
  • Q: Can the timezone in toDateTime be read from a profile attribute? — No, the timezone ID must be a string constant; field references and expressions are not supported.
  • Q: What format does toDuration accept as a string? — ISO-8601 duration format, e.g., "PT10H" for 10 hours or "P1DT2H" for 1 day and 2 hours.
recommendation-more-help
journey-optimizer-help