DatePicker value and Dataset field "Date" type Not working/sorting

Hey everyone,

I have a datepicker on a form which saves into a dataset field which is set to Date type.

The date gets saved into the field but there is a little orange triangle next to it which says “the value does not match the field type Date” even though it is directly from the date picker?

I am trying to sort the fields by this date value too which isn’t working for a repeater, currently I am using the .setSort function by .ascending but it is mixing up the dates ie:

April 12 is coming up before April 3 because of the 1

Any thoughts on how this can be fixed?

1 Like

Hey @miran-stubican did you ever get an answer to this. My dataset is doing this also?

Does your Date field include time, or is it the date only?

If it is date only, the date format that must be inserted is the following:

`${year}-${month}-${date}`
"2024-03-22"

Note that your month and date must be zero-padded and if you’re using the getMonth() function on the value of your date field in the form, you need to increment it, as January is month 0. Here is the code that works for me:

$w.onReady(function () {
    $w('#btnSubmit').onClick(() => {
        const dateValue= $w('#dateField').value;
        const year = dateValue.getFullYear();
        const month = (dateValue.getMonth() + 1).toString().padStart(2, '0');
        const date = dateValue.getDate().toString().padStart(2, '0');

        const toInsert= {
            date: `${year}-${month}-${date}`, 
        }

		wixData.insert(DATABASE_ID, toInsert);
    })
});