[Solved] Text field (string) into value (date) via backend function

Hello,

I try to get date values from my googlesheets thru zapier to Wix via backend function. The function itself works fine for Numbers and text, but I´m not sure how to change it to value date.


So basically the red underlined needs to be changed automatically via backend code into the green underlined one.

Any ideas?

Here is my backend code (without the date value):


I would need to add:
“date” : toDate(body.date)

Thx

Hi, before you insert it into the database collection , ypu need top convert it into Date.

Like:

let recodeInsert = {
//your numeric fields as you posted above....,
datum: new Date(body.Datum)
};

P.S, if you already imported everything and you don’t want to delete and import again, you can run a query like this:

import wixData from 'wix-data';
export async function fixDateFormat(){
let items;
return wixData.query('CollectionName')
.isNotEmpty('datum').limit(1000).find()
.then(r => {
items = r.items.map(e => {
e.datum = new Date(e.datum);
return e;
});
return wixData.bulkUpdate('CollectionName', items);
}

Hi J.D.,
I added the code and it looks like this now:

Never the less it appears wrong in my database.
I guess I missed something right?

Is this field type set to Date&Time? Are you sure the body field is Datum?

No it´s just set to date and the field key is “datum”


I send the data via Zapier and it works fine for all fields. I just need to change the date format for Wix.

Tick the Zeitfeld checkbox.

I did that and still get the data this way:

FYI: I receive the data via data forms Wix automation thru zapier to my googlesheets. Basically my members are filling out a form and clicking the send button. Afterwards a new spreadsheet in googlesheets is takingthis data, adding some new columns and sending it back via Zapier to my database in Wix via backend_function.

So basically the date format I receive in googlesheets is from Wix data forms and I just want to play it back to my database in the correct format.

When you export the date from you database, it converts into ISO date format (or other string formats).
In order to convert it into Date again you should use the
new Date(dateString)

Maybe the string format in your case is not supported.

You can try installing NPM like moment which lets you do a lot of things with time&dates including formatting.

See about NPMs in Wix:

https://support.wix.com/en/article/velo-working-with-npm-packages

Moment.JS docs:
https://momentjs.com/docs/

Thanks for the links.