Update date field, one Month off

Hi,
I have a database with a date field,
when I do a basic update query to update a record with a new date, the Month is one Month off…
Say I insert 2021-03-24 in the database it becomes 2021-02-24. And when I insert a date in January, say, 2021-01-15 the database record becomes 1970-01-01

I cannot figure out why this happens. Perhaps anyone know why this occurs?

M

Getting the months from a date gets the value from an array of the month names and therefore are integers starting at 0. So Jan = 0, Feb = 1, Mar = 2 etc.

It’s the same as other arrays they start with an index of 0 so the first value in an array has an index of 0 rather than 1.

No idea what is the problem with the first example from the information given but in the second example 1970-01-01 is the default date set when no value is sent to the update suggesting the data sent is either null or invalid

Whats the DB type?
Also what happens when you run the expected update query directly on the SQL server?

Most likely the value you are trying to inset is not what you think. Maybe double check the value actually being sent to server action and update query step.
This most likely does not have anything to do with NodeJS, unless the value being parsed by NodeJS server is causing the month values to change.

The problem also appears when I use a date picker in my form. When de database receives the value (say 2021-01-01) it ends up being 2021-00-01 which is invalid and then becomes the 1970-01-01 value i think.

DB is a MySQL database and running as a NodeJS project within local Docker.

You should check the network tab for the request made to server action - in the request body what do you see the date value passed to server action?

If that looks ok, next is checking the value read by server action.
Add a set value step in the server action with value as {{$_GET}} OR {{$_POST}} and output ON. The response will tell you what the server action is reading the input as.

Even more strange; when I set the date in the Database manager in Wappler to a date in january, then re-fetch the data, it is 1970 again…

What database filed is that? How do you update the date (i.e. what’s the exact value being sent) and are you sure that’s not just displayed wrongly in the database manager?

It is a NodeJS project created all with Wappler.
Field type is ‘Date’

Ok so when you say you update the record - how do you do this? What value do you send to the database field? What database are you using?

as you can see in the video in my post, I changed the date using the field type popup date picker.
Database MySQL 8.0.x
Hosting type: Docker Hosting
Server model: Node JS

I am not referring to the database manager.
In your first step you say that you:

How exactly are you doing this - show some screenshots where we can see what you are doing and explain this step by step.

Teodor, I am watching the table now in an external program (RazorSQL) and there the data displays the correct dates.

So the issue seems to be with the database manager not displaying it correctly? But the values are inserted correctly?

seems like it, now I also have to check if I retrieve the data which comes back, that I can do later today

You can just run a server action with a database query directly in your browser and check the results. Most probably this is just an UI problem in the database manager and we will check it after our Christmas break.

Yes, I’ll investigate further to see where the problem is and keep u updated.

Have a great New years eve!

1 Like