Posting a date from a 'Date Picker' component


I am trying to save some data back to the database and one of the values is a date that is chosen from the ‘Date Picker’ component. When I try to do a POST request to the database, it throws an error for the date value and says the date is null. I am assuming I am not handling the date variable properly. I would appreciate any help with regards saving this date value.

See below a screenshot of the data I am trying to post to the database and the error I get back. When I make the date value empty, I get a successful save to the database

Screenshot - Sample Data 5


A bit of update. I had an error with the name of the variable the date was being stored in from the Date Picker. However, after correcting this and trying to save the data again, I still get an error, but no longer the error that indicates the variable is null. I am still assuming I am not properly handling the data type properly, but I am not certain of how to fix this. See the updated error I am getting now below.

Screenshot - Sample Data 6

Could you please send us a screenshot of the request? (you need to open Dev Tools (F12) and find tabs: headers, preview, networks.
We need all of them + the body of request.
image (79)
PS usually 400 error means that the request is not valid or the server is not working properly

Hi Artem,

Okay, I did F12 and below are screenshots of the error.

I am assuming there is a Javascript native method I need to invoke to get the date in the right datetime format, in order for the database to accept the date param, but I am not sure which native method I am supposed to be calling (similar to the .toDateString() you had recommended I use in a different forum post).


Perfect! We are absolutely sure that the problem is how the data specifies.
Please share the screen how you receive this data.

See screen shots below. I am choosing a date using the Date Picker component and then assigning the value to the raw data being sent as part of the POST http request message to the database.

Screenshot - Sample Data 14

Note, please disregard the ‘new Date()’ expression you see in the screen shot. It is a left over of recent changes I made while troubleshooting the error. The new Date expression was not in the POST message when I sent you the screenshots from the F12 Dev tools screen.

Could you please share the link to your project?

Hi Artem. I forgot to update this thread on my progress with this. I ended up doing some research and trying the below date method, and it ‘looks’ like it is working.

const timeStamp = mobDate.getTime();

I used getTime() to convert the date to a timestamp and the database call now works. However, I now have a problem where another input field is failing to get updated in the database, but I am not sure if it is due to something new I introduced or a bug in the system. I will dig around a bit more to see if I can fix the new issue I am seeing.


Update. I have figured out the issue I was having and I am now able to successfully save a timestamp value to the database after getting a date value using the Date Picker. So using the .getTime() Date method is the solution it appears.

1 Like