Why when it runs the data get inverted? HELP I nedd yyyy-mm-dd
*Some nodes are exactly the same and it does not invert! weird
*Some nodes are exactly the same and it does not invert! weird
Hey @Fernanda_Silva,
Can you share the workflow and the input json data? That is a pretty big expression to manually type out
Maybe you can help me solve my problem in a simpler way:
I need these fields, which are dates, to be converted to GMT -3, for Brazil, in the format yyyy-mm-dd (ISO format). I tried using the Date Time node, but it disrupted my workflow entirely.
(above, i guess i have encounter the problem : change LocaleString to .toISOString())
Hi @Fernanda_Silva, any chance you can share the actual input values you are trying to transform? Working with dates can be tricky as there is a plethora of different formats, so seeing what your current data looks like will help getting the transformation right.
Hello,
Well, let me explain. The date comes in this format, for example:
“2023-06-19 13:37:34”
The first issue is the time zone. Supposedly, my flows are already set to GMT -3 Sao Paulo, but the hour is +3 instead of -3. So, I made a workaround to return the date in the same format (yyyy-mm-dd hh-mm-ss) and subtract 3 hours. In other words, the expression:
{{ new Date(new Date($node[‘Update Deal’].json.update_time).getTime() - (3 * 60 * 60 * 1000)).toISOString().replace(‘T’, ’ ').slice(0, -5).replace(/(\d{4})-(\d{2})-(\d{2}), (\d{2}):(\d{2}):(\d{2})/, ‘$1-$2-$3 $4:$5:$6’).replace(///g, ‘-’) }}
will return:
“2023-06-19 10:37:34”
Thank you. Assuming this time already represents America/Sao_Paulo
time, you can parse it like so using Luxon (where $json.SaoPauloTimestamp
references the incoming data):
{{ DateTime.fromFormat($json.SaoPauloTimestamp, "yyyy-MM-dd HH:mm:ss", { "zone": "America/Sao_Paulo" }) }}
Parsing UTC time works pretty much the same:
{{ DateTime.fromFormat($json.UtcTimestamp, "yyyy-MM-dd HH:mm:ss", { "zone": "UTC" }) }}
Now with this Luxon object you can easily format it just the way you want using the .toFormat() method. For the format you’d like to see, simply append .toFormat("yyyy-MM-dd")
to the example expression above. In a workflow this could look like so:
Lastly, if for any reason you need to change the time zone on the fly you can do this by adding .setZone() to your expression like this:
{{
DateTime
.fromFormat($json.UtcTimestamp, "yyyy-MM-dd HH:mm:ss", { "zone": "UTC" })
.setZone("Asia/Tokyo")
.toFormat("yyyy-MM-dd HH:mm:ss")
}}
These examples should all work regardless of your workflow, instance, or server time zone settings. Hope this helps when working with time stamps and time zones
wow this Luxon code is so elegant!
Thank you very much, I’m going to go read the documentation right away!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.