Saving a date to the database

This is probably a rookie error, but I am having trouble setting a date column in the database. The schema is shown here:

I have tried this:

with this error:

and this:

with this error:

I have also tried a simple string of the format ā€œ05/20/2016 03:58:23ā€

  1. How do I put a date object into an object which I can save to the database?
  2. If I need to turn it into a string first, what is the preferred format?

Thanks.

Hi @Andrew_Schox

I think the problem is because of misspell.
The table column is named timestamp but the codeless logic uses timeStamp name.
You should rename timeStamp to timestamp in your Create Object block.

Best Regards,
Maksym

Thank you. That worked. Iā€™m still not sure of the rule for what I should put into an object to save a date. So for example in this block. 1 runs fine, but 2 does not with the following error reported:

Fri Sep 11 2020 17:41:56 GMT+0800 (Australian Western Standard Time) | SERVER_CODE | ERROR | [6506] TypeError: CurrentUpdate.start.getTime is not a function at Object.execute (/opt/backendless/repo/95594b0a-1972-7690-ff14-f883764c3b00/files/servercode/CODELESS/default/PRODUCTION/timers/update.js:34:135) at processTicksAndRejections (internal/process/task_queues.js:97:5)

timeStamp, start and end are definitely of type DATETIME and I have been able to successfully write dates to the start and end columns using this codeless save object block.

Maybe I should not be using convert to timestamp for date? Or Iā€™m missing something else?

There is no need to wrap the Date into Convert to timestamp block.
You can directly pass the Date for start and end columns.

If you want to set the Date with offset, you can also pass the Date directly into Offset Date block. No need for convert block.

See my example:

I already tried that, but I still get an error.

Fri Sep 11 2020 18:42:28 GMT+0800 (Australian Western Standard Time) | SERVER_CODE | ERROR | [27153] TypeError: CurrentUpdate.start.getTime is not a function at Object.execute (/opt/backendless/repo/95594b0a-1972-7690-ff14-f883764c3b00/files/servercode/CODELESS/default/PRODUCTION/timers/update.js:33:134) at processTicksAndRejections (internal/process/task_queues.js:97:5)

I reproduced your problem. In case you get the date property of the object, it should be wrapped into date from timestamp block because the date from the server is received as a timestamp.
So your code blocks should look like this:

Thank you. That worked perfectly!

  • Can I suggest that a little bit of documentation for each block in the Codeless Blocks Reference (and maybe in the tooltips for every block) would be helpful for this sort of question?
  • The other thing that would be handy for a newbie to this environment is some documentation on types, type coercion, and other general tips about passing data backwards and forward within Backendless.
1 Like

Hello @Andrew_Schox

This is a good proposal, I will discuss it with our team.

Thank you for your suggestion.