DateTimeDiff returning null in Architect expression

Expression evaluation failed: Invalid date format. Expected ISO 8601 but got ‘2023-10-27’.

Trying to calculate days since last interaction. Using this in Architect:

DateTimeDiff(GetDateTime("now"), GetDateTime("${interaction.last_contact_date}"))

The variable last_contact_date comes from an external API payload. It looks like this:

{
 "last_contact_date": "2023-10-27"
}

The expression returns null and the flow fails. I tried adding T00:00:00Z manually in the expression but Architect complains about syntax. Is there a way to coerce the string format before passing it to DateTimeDiff? Or do I need to use a different function like GetDayOfWeek to validate it first? The SDK documentation for the expression evaluator is sparse on date coercion rules. Any working snippet examples for date arithmetic in Architect would help.

I typically get around this by forcing the string into a full ISO 8601 format before passing it to GetDateTime. Architect is strict about time components and will reject bare date strings like “2023-10-27”.

You need to append the time and timezone offset manually using string concatenation. Try this expression to normalize the input first: Append("${interaction.last_contact_date}", "T00:00:00Z").

Then wrap that normalized string in your GetDateTime call. It looks like DateTimeDiff(GetDateTime("now"), GetDateTime(Append("${interaction.last_contact_date}", "T00:00:00Z"))). This ensures the parser sees a valid timestamp.

DateTimeDiff returning null in Architect expression

Have you tried wrapping the date string in ParseISO8601DateTime instead of manually concatenating the time suffix? It handles the timezone offset parsing internally and prevents the format mismatch you’re seeing with GetDateTime.

DateTimeDiff(GetDateTime("now"), ParseISO8601DateTime(Append("${interaction.last_contact_date}", "T00:00:00+00:00")))

I’d recommend looking at at environment drift if you apply this fix manually. Hardcoding string manipulation in Architect bypasses our Terraform state, making promotions to staging or prod inconsistent.

Use the CX as Code module to define the expression logic in a JSON file instead. This ensures the Append normalization is version-controlled and deployed atomically across all workspaces.

You need to append the time component before parsing. Architect’s DateTimeDiff expects full ISO 8601.

DateTimeDiff(GetDateTime("now"), GetDateTime(Append("${interaction.last_contact_date}", "T00:00:00Z")))

I define these expressions in Pulumi stacks to ensure consistency across environments. Manual edits in the UI cause drift.