Set date based on user tImezone

Did not yet work on it but a client asked to pick timezone before setting a day. The idea is that user picks his timezone and then when making an update, the date field is updated based on his timezone. Any ideas on how to approach this? Will give feedback if having progress.

Thank you!

Hi Niko,
You can use UTC time for your datetime variable and then sum the hours (depending on selected timezone).

1 Like

For example something like this? UTC + America/Antigua
Typing it in rough mode not how Wappler will display it. Just to check if I get the idea right.


Now that I re-read your answer, how can I sum the hours. I mean PHP timezones are in the format of text, where I could retrieve the difference in hours. Will it work If I retrieve from the database the timezone user has selected? (for example America/Adak)

Use UTC time and after add hours through the data formatter. Better of you get DB with all timezone with + and - with all zone. Same as you have a date and use add days function.

Thank you very much. Any idea on where to get the + - hours difference? In php timezone I only find names

The date value in the database what should it be. With timestamp I am getting an error when trying to add the UTC

Should I use the Date Add or the SUM?


also this might help

I would use date add because if your database stores -2 for Africa or +6 for Australia or whatever then you could have NOW date add hours and it should work very well because the parameter it takes is exactly -2 or +6 etc.

Thank you very much for your respone. Strange thing is that I whatever I try it does not add. All 3 attempts add the same datetime.


timezone_diff = -10

PS. I mean they do not change datetime. They add if I was just adding {{NOW}} the timezone_dif does not make any difference

I will stop here and come with the final result, The issue must be in the timezone_diff value. I typed -10 and it worked.

Strange, if I hardtype the -10 it will work. As dynamic value it won’t. What kind of datatype should it be on the database?

The issue is when negative value. Changed -10 in the database to 5 and it worked

Well don’t know what happened. Right after I changed the value back to negative inside the database it worked! Thank you guys, I will try to create a small tutorial on this.

Many tacos to @psweb @updates and @Teodor



Glad it is working now, wonder why it did not work a little while back. Seems strange. I wonder what happens with date add if it is 01:00 and the date add is set to hours and you input -2 needing it to go back to 23:00 on the previous day? I’m sure it’s working but just wondering why -5 worked and -10 not

It was 5 and -10. While initially I was trying to make it work with -10, when changed to 5 it worked. Then re-entered -10 and it worked that too. Who knows maybe it was something else, because I was changing other things too, that made it work with negative values too. Again thank you vey much for your help.

1 Like

I’m having a similar issue where the negative value break the addHours function. I’ve not been able to fix it, but what I can tell is that in my case it doesn’t matter if it goes onto the day before or not, it’s just the negative value itself. There also seems to be an issue where days are added on top of hours, unintendidly.

Postgresql can change the timezone directly when querying. ej:

select created_at at time zone 'utc' at time zone 'america/los_angeles'
from users;

You can find supported timezones with this query:
select * from pg_timezone_names;

Another option is to use

Adding or subtracting hours could be complicated when dealing with daylight saving rules across the globe.