# Problem with Dates



**URL:** <https://forum.wixstudio.com/t/problem-with-dates/21572>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 21, 2020, 10:48am UTC](https://forum.wixstudio.com/t/problem-with-dates/21572 "2020-05-21T10:48:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vassil-dimitrov](https://avatars.discourse-cdn.com/v4/letter/v/9de053/32.png) [@vassil-dimitrov](https://forum.wixstudio.com/u/vassil-dimitrov)\
**Post date:** [May 21, 2020, 10:48am UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/1 "2020-05-21T10:48:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GraceGrabillo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gracegrabillo/32/87012_2.png) [@GraceGrabillo](https://forum.wixstudio.com/u/GraceGrabillo)\
**Post date:** [April 23, 2024, 12:26am UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/2 "2024-04-23T00:26:20Z")

</div>

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](https://us1.discourse-cdn.com/wix/original/3X/d/0/d0ebd7ead7c81e5f1624b8539e4bdea429ff80a2.png)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 23, 2024, 10:37am UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/3 "2024-04-23T10:37:26Z")

</div>

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 …

> [@How to query a date field and show with a lamp if it isn´t empty?](https://forum.wixstudio.com/t/how-to-query-a-date-field-and-show-with-a-lamp-if-it-isn-t-empty/6603/6):
>
> Instead of using —\> nicknames —\> maybe you can use the → OWNER-ID → " \_owner " All you need are two dates, right? → STARTING-DATE and EXPIRE-DATE to be able to calculate between these 2 dates. You also can break down date and time to a unique unit called → TIMESTAMP \<— and with these timestamps you can calculate very easy. You can use some online time-converter, like… [Epoch Converter - Unix Timestamp Converter](https://www.epochconverter.com/) You can install → MOMENT.JS in your project, to work more easy with dates and t…

…or this one..

> [@Code for the time difference in hours in a time picker](https://forum.wixstudio.com/t/code-for-the-time-difference-in-hours-in-a-time-picker/37475/4):
>
> I will keep your post in mind. Will answer tomorrow. …to be continued…

…or this one…

> [@How to add an hour (or more) to timepicker value?](https://forum.wixstudio.com/t/how-to-add-an-hour-or-more-to-timepicker-value/4443):
>
> Hi everyone, is there a way to change the value of a timepicker to any number of hours, minutes and Seconds to add? Here’s an example: Someone decides to attend an event. The event starts at 8 am and lasts approximately 1.5 hours. I would now like to display the time by which you are finished. Does anyone have any ideas about this? I tried to add an addhour element to the timepicker, but it didn’t work. I had imagined the following: Date newDate = DateUtils.addHours(oldDate, 3);

…and this one…

> [@convert timestamp to normal date](https://forum.wixstudio.com/t/convert-timestamp-to-normal-date/4425/9):
>
> No problem and like always → do not forget to like it, if you really liked it wink

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

---

<div class="post-metadata">

**Author:** ![GraceGrabillo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gracegrabillo/32/87012_2.png) [@GraceGrabillo](https://forum.wixstudio.com/u/GraceGrabillo)\
**Post date:** [April 23, 2024, 8:43pm UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/4 "2024-04-23T20:43:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GraceGrabillo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gracegrabillo/32/87012_2.png) [@GraceGrabillo](https://forum.wixstudio.com/u/GraceGrabillo)\
**Post date:** [April 23, 2024, 11:10pm UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/5 "2024-04-23T23:10:04Z")

</div>

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:

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

```

On the console, it gives the correct format:

 ![console](https://us1.discourse-cdn.com/wix/original/3X/d/1/d198353b6adf64cebc50b2452589353653eeedeb.png)

I have this insert code:

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

```

But when looking at the collection, the yellow icon is still there!  
 ![image](https://us1.discourse-cdn.com/wix/original/3X/4/c/4c472577e5b3826dbad6104a67ab18487bea9e20.png)

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.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [April 24, 2024, 10:46am UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/6 "2024-04-24T10:46:52Z")

</div>

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](https://us1.discourse-cdn.com/wix/original/3X/7/1/71f99e3e9d1fc3814660293d7b867338d9d8a7cb.png)

**DO YOU RECOGNIZE SOMETHING SIMILAR, REGARDING YOUR ISSUE ?**

Maybe this is also interesting for you…

> [@Visual Learner - coding a repeater](https://forum.wixstudio.com/t/visual-learner-coding-a-repeater/3010/15):
>
> @jfriede As promised —\> here it is! —\> [https://www.media-junkie.com/datepicker](https://www.media-junkie.com/datepicker) This is your interactive-example-slot. Your database… How to use this "interactive-example? You can use the predefined DATABASE → “SportSheduler” You can see, which fields are already activated and ready to use. Setup one of the 4 given DB-Presets/Slots to get your DATABASE connected. Example… You will have to change the PRESET/SLOT for —\> “SportSheduler” 4) General-Settings: …

---

<div class="post-metadata">

**Author:** ![GraceGrabillo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/gracegrabillo/32/87012_2.png) [@GraceGrabillo](https://forum.wixstudio.com/u/GraceGrabillo)\
**Post date:** [April 24, 2024, 1:59pm UTC](https://forum.wixstudio.com/t/problem-with-dates/21572/7 "2024-04-24T13:59:58Z")

</div>

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.
