fxholl
April 10, 2024, 2:41pm
1
Describe the problem/error/question
I am using the following expression to convert a GMT date and time to Brasil timezone:
{{ DateTime.fromFormat($json[‘Submitted at’], ‘yyyy-MM-dd HH:mm:ss’, { zone: ‘utc’ }).setZone(‘America/Sao_Paulo’).toFormat(‘yyyy-MM-dd HH:mm:ss’)}}
It usually works, like in this case:
However it sometimes returns an error:
Can someone help me understand what I am doing wrong?
Please share your workflow
Share the output returned by the last node
Information on your n8n setup
n8n version: v1.31.2
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
liam
April 10, 2024, 2:51pm
2
Oi! Tudo bem?
The reason is your time format is actually H:mm:ss
not HH:mm:ss
. You can tell because the hour in your screenshot is 2 instead of 02. It works sometimes because any time after 10:00 in the H
format would be able to be parsed by the HH
format
change your expression to this and it will work:
{{ DateTime.fromFormat($json['Submitted at'], 'yyyy-MM-dd H:mm:ss', { zone: 'utc' }).setZone('America/Sao_Paulo').toFormat('yyyy-MM-dd HH:mm:ss')}}
All i changed was the HH to H in the .fromFormat
method
2 Likes
fxholl
April 10, 2024, 5:56pm
3
awesome!
I will test and report back
system
Closed
April 21, 2024, 1:51pm
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.