Invalid DateTime issue

Hello everyone, I have an issue with DateTime. I searched the forum, but other issues seem to be different from mine.

Below I attached a screenshot from execution log. Here I use an Edit Fields node to convert the timestamp I get from a Data Table → Get Rows node. The preview shows it should work fine, but the actual output gives me “Invalid DateTime“.

I do not know how to debug this, any help would be appreciated~

Information on your n8n setup

  • n8n version: 1.123.4
  • Database (default: SQLite): n8n built-in
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: debian

Hey @enraged_tomato !

If you need the timestamp in milliseconds or seconds in Unix :

{{ DateTime.fromISO($json.open_record.updatedAt).toMillis() }} // ms

{{ DateTime.fromISO($json.open_record.updatedAt).toSeconds() }} // s

Just remove the .toFormat() , since is transforming into what you see rendered by expression.

Cheers!

Hello @Parintele_Damaskin ,

Umm, sorry if I wasn’t clear.

I am trying to get the date time of a DB record in a string with a particular format - “dd/MM/yyyy HH:mm:ss”

{{ DateTime.fromISO($json.open_record.updatedAt).toFormat(‘dd/MM/yyyy HH:mm:ss’) }}

This works fine in the preview, but during runtime it gives me “Invalid DateTime“ as a result

Ahh… my bad, is a preview and runtime conflict it seems.

Maybe trying to force it as string?

{{ DateTime.fromISO($json.open_record.updatedAt.toString()).toFormat(‘dd/MM/yyyy HH:mm:ss’) }}

Or

{{ DateTime.fromISO(String($json.open_record.updatedAt)).toFormat(‘dd/MM/yyyy HH:mm:ss’) }}

Or keep it simple

{{ DateTime.fromISO($json.open_record.updatedAt) }}

ChCurios have 1.113.3 self hostednow.

Cheers!

$json.open_record.updatedAt is already a string. But anyway I tried to force the value into a string - it doesn’t help, I am still getting the same issue

This would return a DateTime object, but I need a formatted string

Okay, I’ve made a simple workflow to share. It would be nice if you can try running this on your instance and see if it behaves the same. You can query any DB that has at least 1 record - it should have the “updatedAt” field by default.

1 Like

Yep…. @enraged_tomato
The behaviour with the DateTime from the data tabels is at runtime your expression is handleded as object(but if you run the code directly it treatwed as string.), tried 2 ways…

Now, the other option is opposite, if you run the workflow, is not valid, and run individual node is valid.

Just twisted my brain lol…

And here is when you run the node.

cbc1pgdc

Dont know for sure which version is thhe one that n8n reccomends…hmm… i will check again the dcs with Luxon and Date.

Cheers!

EDIT:

This one works well :

{{ $json.updatedAt.toDateTime().setZone(‘Europe/London’).toFormat(‘dd/MM/yyyy HH:mm:ss’) }}

1 Like

Omg, that is weird. Is that a bug even? Maybe I need to report it

Hey @enraged_tomato !

Just tried this , and it works as intended… when i run the workflow, and when i run the node alone:

{{ $json.updatedAt.toDateTime().setZone(‘Europe/London’).toFormat(‘dd/MM/yyyy HH:mm:ss’) }}

Cheers!

2 Likes

@Parintele_Damaskin thank you, I’ll just go with your suggestion for now and raise a bug ticket for the inconsistency between preview and runtime

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.