Formula to transform Date in GMT GMT -3 returns Invalid Date

My workflow receives a date in this format 2024-06-27T13:44:07.000Z

and I need to convert it to GMT -3 (Brazil).

I applied the formula that was suggested in another post on the comḿunity board, but this time the formula returns an invalide date:

Please share your workflow

My sense is that the error in the formula itself, but i can find the problem:

{{ DateTime.fromFormat($json[“body”][“data”][“createdAt”], ‘yyyy-MM-dd H:mm:ss’, { zone: ‘utc’ }).setZone(‘America/Sao_Paulo’).toFormat(‘yyyy-MM-dd HH:mm:ss’)}}

Information on your n8n setup

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

Hi,

Your format in fromFormat function is not correct.

Below one is the format of your createdAt date.

 yyyy-MM-dd'T'HH:mm:ss.SSS'Z'

So,

{{ DateTime.fromFormat($json["body"]["data"]["createdAt"], "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", { zone: 'utc' }).setZone('America/Sao_Paulo').toFormat('yyyy-MM-dd HH:mm:ss')}}

Alternative with fromISO,

{{ DateTime.fromISO($json["body"]["data"]["createdAt"], { zone: 'utc' }).setZone('America/Sao_Paulo').toFormat('yyyy-MM-dd HH:mm:ss') }}

I hope it helps.

2 Likes

worked like a charm! thank you!!

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