Invalid DateTime in Set Node

Describe the problem/error/question

I am getting the _createTime value from a Google Cloud Firestore node and I am trying to format it to something Nocodb can take. However, I keep getting the invalid DateTime error. This was working previously in an earlier N8N release. Is there someone that could let me know why I am getting the error? Thanks.

{{ DateTime.fromISO($json["_createTime"]).toFormat('yyyy-MM-dd hh:mm:ss') }}

What is the error message (if any)?

Invalidate DateTime

Please share your workflow

Share the output returned by the last node


[
{
"created_date":
"Invalid DateTime"
}
]

Information on your n8n setup

  • n8n version: 0.231.2
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu 22.04 LTS

YOU CAN TRY:

{{ new Date($json[ā€œ_createTimeā€]).toISOString().replace(ā€˜T’, ’ ').slice(0, -5) }}
or
{{ DateTime.fromISO($json[ā€œ_createTimeā€]).toUTC().toFormat(ā€˜yyyy-MM-dd HH:mm:ss’) }}

Thanks Fernanda.

{{ new Date($json["_createTime"]).toISOString().replace('T', ' ').slice(0, -5) }} 

works for me, but

{{ DateTime.fromISO($json["_createTime"]).toUTC().toFormat('yyyy-MM-dd HH:mm:ss') }}

does not.

1 Like

It turns out the Timezone in the workflow Settings set to default seemed to have caused the error.

image

Once I’ve changed it to my local timezone, the original DateTime code works again.

{{ DateTime.fromISO($json["_createTime"]).toFormat('yyyy-MM-dd hh:mm:ss') }}

image

No more ā€œInvalid DateTimeā€.

image

3 Likes

Amazing! I was having an issue today with the timezone too, mine was GMT -3 Sao Paulo, but it was setting it wrong so i had to search a solution to subtract 3 hours… :frowning:

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