Problem with Dates

Hello ,
I have a strange problem with dates. When I take a date from DatePicker in Front end page it shows date as Thu May 21 2020 00:00:00 GMT+0300 (Eastern European Summer Time)

Then When I transfer the same variable to backend function and print into console same variable it shows : 2020-05-20T21:00:00.000Z
Can someone help me how to make them equal ?

Best Regards,

Vasil

No fix from Wix? I am having the same problem. I don’t know where to parse since the date format showing on the console is the thing that I want, but on the backend data its different and shows a yellow mark telling its invalid format.

image

There are different time-formats you can use.
In general, when working with times → you probably should work with → TIMESTAMPS ← do the calculation and convert it to the time-format of your choice after calculation.

Also you maybe want first to check what kind of format is setted up inside of your database. As long as you did not setted-up the format of a DB-Field it will get the yellow WARNING-SIGN inside of your DB.

Also read the following post …

…or this one…

…or this one…

…and this one…

Convert your date to the right format, which is expected by your DATABASE.

Thanks @CODE-NINJA I’ll check moment.js and will update if it works or not.

Ok, so browsing the documentation, I was presupposed that moment.js is the thing I need.
In my code, I converted the value on the datepicker element:

let selecteddate = $w('#targetschedule').value;
        let savethedate= moment(selecteddate, true).format("MMM DD, YYYY");

On the console, it gives the correct format:

I have this insert code:

let toInsert = {
            "title": $w('#projecttitle').value,
            "targetDate:": savethedate, ... etc

But when looking at the collection, the yellow icon is still there!
image

I feel like I’m missing something.
I have to go this way because there are values to insert on my content that comes from a selected dynamic page.

Which format does expect the collection ?

Take a look onto the following picture…
2024-04-24 12_44_59-DatePicker Not Submitting to database - Discussion _ Ask a question - Wix Studio

DO YOU RECOGNIZE SOMETHING SIMILAR, REGARDING YOUR ISSUE ?

Maybe this is also interesting for you…

Thank you @CODE-NINJA I’m reading it and somehow its similar in a way he puts the input values on his collection.

I was assuming that since it’s Wix’s datepicker element, it should automatically be the date format on the CMS collection when the data type “Date” is used. Coding it on the front-end to save the datepicker selected value to the CMS should not be the issue.

I’ll get back to you after reading your link and will try to do some tricks and I hope it works.

1 Like