Help wanted on how to properly save date to database (NodeJS with Postgress)

Hi there fellow Wapplers,

I have this strange issue with saving dates to the db. I have a simple form to insert a record with a start and end date as input type date:

When I post the form the record gets saved to the db and all looks well in Wappler’s database manager:
dateinmanager

This is my field settings:

BUT when I query the data the raw output shows the previous day!
previous day

This also happens when I open my edit record modal:

And so each time you save the record the date goes back one day without the user changing anything!

Is this regular behavior or is this a bug?

As per usual any help is greatly appreciated :hugs:

Hi Jelle,

Not sure but I think the issue is related to differences in timezones. I think try to change “Use UTC time” in the date inputs or maybe the timezone setting of the database field

The reason I think it’s related to the timezone is that it’s not showing 1 day before, it’s showing 2 hours before (T22:00)

Thanks for your reply, @htatd.

So now I have set the start date field to use timezone:

Now the issue still occurs BUT the hour went from 22 to 23:

Weirdly enough when I add 1 hour like so:
dmx-bind:value="sc_get_single_dienst.data.get_single_dienst.start.addHours(1)

Seemingly not one but two hours get added!

If I add .toUTCTime to the database insert post value of start I also get 23 hours previous day not 00 hours current day.

So there is something funny going on. This does not happen on my mysql php projects.

Any more thoughts are highly appreciated.

Hi!

I just had the same exact problem.

I assume that your local timezone is UTC/GMT +1 so the 1 hour difference that you see is that you see there the UTC time, which means that it’s actually right.

To display the right time you just use .formatDate(yyyy-MM-dd), it should show the date correctly with your timezone.

For example:

When I don’t use .formatDate() =

Screenshot 2022-02-19 at 01.52.26

When I use .formatDate() =

Screenshot 2022-02-19 at 01.53.06

Sorry for the late reply, remembered about your question when I got the same problem :stuck_out_tongue:

1 Like

Pure gold @htatd! This fixed my issue :+1: :grin: :grin: :heart: THANKS

So on the front end data picker where the date is displayed I added the .formatDate('yyyy-MM-dd') and format="DD-MMM-YYYY" and it works like a charm!

Pretty confusing stuff, these time zones!

1 Like