DateTimeDiff returning negative values in Architect Data Action expression

Just noticed that my date comparison logic is failing in the Data Action JSON mapping. I am trying to filter conversations older than 30 days before sending them to the Snowflake staging table. The expression seems syntactically correct, but the runtime evaluation is off. I am using DateTimeDiff to calculate the delta between the conversation end time and the current timestamp. The result should be positive if the conversation is in the past, but I am seeing negative integers for records that are clearly weeks old. This suggests a timezone mismatch or a unit conversion error in the expression engine.

  • Attempted to use DateTimeDiff([Conversation.EndTimestamp], [System.CurrentTimestamp], "days") but the output was -45 instead of 45 for a record from 45 days ago.
  • Tried swapping the arguments to DateTimeDiff([System.CurrentTimestamp], [Conversation.EndTimestamp], "days") which returned 45, but this feels semantically backwards and I want to confirm if GetDayOfWeek is a better alternative for relative date filtering.

Is DateTimeDiff strictly (Current - Target) or (Target - Current)? The documentation is vague on the sign convention. Here is the failing JSON snippet:

{
 "expression": "DateTimeDiff([Conversation.EndTimestamp], [System.CurrentTimestamp], 'days') > 30"
}

Why is the delta negative?

The problem here is the argument order in the DateTimeDiff function. In Genesys Cloud Architect expressions, the syntax is DateTimeDiff(startDateTime, endDateTime, unit). You are likely passing the current time as the first argument and the conversation end time as the second. If start > end, the result is negative. To get a positive delta for past events, the older timestamp must be the first argument.

For your Snowflake staging filter, you want to identify conversations where the end time is more than 30 days ago. The expression should calculate the difference from the conversation end time to now. Use this structure in your Data Action mapping:

{
 "filter": {
 "type": "boolean",
 "value": "{{DateTimeDiff($conversation.endTime, $now, 'days') > 30}}"
 }
}

Note that $now is not a standard built-in variable in all Architect contexts; ensure you are using the correct system variable for current timestamp, often accessed via DateTimeNow() or a specific system variable depending on your Architect version. If using DateTimeNow(), the expression becomes:

DateTimeDiff($conversation.endTime, DateTimeNow(), 'days') > 30

Also, be aware of timezone handling. $conversation.endTime is stored in UTC. If your $now or DateTimeNow() returns local time, the delta might be off by hours. Always ensure both timestamps are in UTC before diffing. If you are piping this to Snowflake, consider pushing the date filtering logic to the SQL layer if possible, as Architect Data Actions have payload size limits and evaluating complex date logic on high-volume conversation streams can cause throttling or 413 errors if the batch size is too large.

  • Verify DateTimeDiff argument order (start, end, unit)
  • Check timezone consistency (UTC vs Local)
  • Review Architect expression evaluation limits
  • Consider offloading date filtering to downstream SQL

The argument order fix worked. I swapped the parameters to DateTimeDiff(conversation.endTime, now(), 'days') and the negative values disappeared. The logic now correctly identifies records older than 30 days for the Snowflake export.

For anyone else hitting this while integrating with external alerting systems like PagerDuty, be careful with timezones. Architect evaluates expressions in UTC. If your source data is local time, you might need to adjust before diffing. I use this pattern in my webhook processors to ensure SLA breaches are calculated correctly across timezones.

"delta": "${DateTimeDiff(conversation.endTime, now(), 'days')}"

Always validate the unit argument too. Using ‘seconds’ instead of ‘days’ can cause overflow issues in downstream JSON schemas if not handled.

  • UTC vs Local time conversion in Architect
  • Handling null timestamps in DateTimeDiff
  • Architect expression debugging tools