Server side time verses app time

Hi, just wondering what best practice is on the following.

In my app the ‘Date and Time’ successfully returns my local date and time.

But on the server side NOW returns a time that is 12 hours behind, I do not know why but presumably that is where my MySQL is hosted or where wappler server time is coming from.

To get an accurate local time into my data I could send a local time from the app to the server, but that seems a waste when NOW is sittng there waiting to be utilised.

Any ideas?

Hello,

NOW on the server side (in your server action) uses the time zone your server is set to.
NOW on the client side (on the page) uses the users local time.

1 Like

When you say server do you mean database or wappler?

Am i able to set the server time to my local time or is that out of reach?

Otherwise, does NOW (on the server) have any purpose?

I mean your web server where you host your site.

Database Hosting Server

Not usually unless you have your own server.

Best for if you need to order your records in exact order they were entered in. Using it one client side will use the users computer time. So if someone on Eastern Time Zone enters something first and someone from Western time enters something and you sort by date and time it will not show in the same order it was entered.

I use client side for some things and server side for time ordering functions.

1 Like

I see, thank you for clarifying, I know what to do now.

Presumaby NOW_UTC is the same no matter whether on the Server or App?

Yes, NOW_UTC returns the time in UTC time zone.

Hi teodor, one more question.
Obviously now, all time should be stored as UTC, but, later, to display the time on local time an offset has to be calculated.
In the app side, there is a function that seems tempting to help to be used to calculate the offset…

image

So i fed fhis into the dynamic attribute of a text input box , but teh result only gives me back the local time, am i missing something?

image

The first date is my local time, the second date has toUTCDAte() function applied, but both are the same as your can see. Last time i looked a I dont kive in greenwich, england.

It would be marvelous if wapplers rich function library could be enhanced with a toLocalTime() function that uses the local timezone calculated aganst a UTC datetime parameter.

Further to the above, when I was not watching, teh UTC time corrected itself

image

How about that!

1 Like

So are you saying the function converts the UTC time record from the database to local time on the front end, or is it just displaying local time on the input before submitting?

A function that did the conversion would be ideal without having to work out the difference, recording the hours and mins against the user and then use this to convert UTC to the correct local time.

As an X Bubble.io user this is one thing they had nailed early on and did really well, you didn’t need to think about it.

Time conversions on complex processes can send you batty and waste so much time getting your head around it.

It would be great if Wappler had a good automagical solution for this!

Hi folks!

I struggled with all of this, and ended up with a good solution documented here:

Please Help Me With An Idiot’s Guide to Converting UTC to Local Times

1 Like