Capturing today's date for CMS field

Question:
How to update a CMS record field with TODAY’S DATE using Velo code.

Product:
I am using Wix Editor and velo scripts.

I want to record the date that my archived photo has been released for viewing. I am using a CMS record with various descriptive fields for each Archive item. We research and then update each archive items before publishing and at that point I want to record the date. I have tried capturing “today’s” date using -

const d = new Date();

But am getting error message “Value does not match field Type”.

I can use that new Date and convert to local/string -

const javaDate = new Date();
const textDate = javaDate.toLocaleDateString();

That works but creates a text field which I don’t wont. I need to sort on it.

WIX covers lots of detail using the Date Picker but can’t find how to use simply System date.
This should be easy but. . .

Inserting a date into a CMS collection field depends on the field data type and options.

It’s important to check whether “Include time field” is selected as it will affect how you need to insert data into your CMS collection.

If you have a “Date” Field without “Include time field” selected, the string that is written to the collection must be in ISO 8601 format without the time.

Example

let dateObject = new Date();
let toInsert = {
    "_id": "00001",
    "title": "Item 01",
    "date": dateObject.toISOString().substring(0, 10)
};

If you have a “Date” Field with “Include time field” selected, the string must be written to the collection using a JavaScript Date Object.

Example

let dateObject = new Date();
let toInsert = {
    "_id": "00001",
    "title": "Item 01",
    "date": dateObject
};

For more information check out the documentation below:

1 Like