Change hours to function not returing expected hour

Not sure this is a timezone-related issue or not.

I am chaning the current date/time with results from an API’s date formatted as text.

The date comest in as: 2023-12-13T14:03:27

First I extract its components

image

Then feed its components to the change year, change month, change date, change hour, change minutes and change seconds functions.

image

All work as expected except the change hours. We can see the date and time elements in the database and the final result:

We are located at GMT+7 and it seems to add 7 hours to the date.

How do I manage that?

1 Like

I just tested this and it works fine for me, which leads me to believe it’s not timezone related. Is it adding 7 hours every time or is just in this one case?

Tested several times and it adds 7 every time.

image

It would be quite coincidental that we are at GMT + 7 and the app conveniently adds + 7 h don’t you think? What else but a timezone issue could it be?

In the second record we’d expect to see 1:32pm if it were adding 7 hours every time. Instead there’s a difference of 17 hours. Have you gone through it step by step in the debugger to see what’s going on?

The second record is doing -7 h previous day (11 pm 24 March instead of 6 am 25 March).

That is not consistent, but it is still a 7 h difference.

This is a backend workflow. All I can see is what’s in the logs and we’re not getting any further with them:

Is this an API workflow? If so, do you have the timezone ID set to UTC?

I do not have these options:

I was able to replicate your issue by changing the timezone of the api worflow to UTC. In this instance the hour is set in UTC so when I view it my timezone (GMT+8) I see it as the extracted hours value + 8 . Maybe the same is happening in your case, although that doesn’t explain the -7 change. What is the origin of this workflow’s trigger…browser, webhook, db trigger, etc?

By the way, you can enable timezone overrides in the app settings

1 Like

Perfect match now, thank you!

image

Jesus christ, this is definitely not the best way to be doing whatever it is you’re trying to do.

Why aren’t you just setting the date field to the API’s response directly? If it detects it as a text, change the response type to date by clicking ‘manually enter API response’ on the API call, then saving, then setting the relevant field to date.

I promise you’ll kick yourself for writing this expression!

That’s a great tip I didn’t know about. However, the data from our API comes back encrypted as a single field. Then we need to decrypt it and so we get a single JSON string instead.

Oh, well that is certainly an edge case. I feel your pain.

If you need to do this in multiple places in your app, I’d suggest you put the logic in a custom event that takes the string and returns the date (so, add a return value of type date, and in the custom workflow, just return date = Current date time change years to… etc etc. Then, you don’t need to rebuild the expression multiple times.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.