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?
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.
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.
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?
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
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.