I’m trying to import data from JSON to my Collection via a REST-API.
Every thing is working OK except with a DateTime field that is not importing as DateTime: “The value does not match the field type Date and Time”
I guess I could solve this with a “before insert” hook, but I have not have success with it.
Can somebody help me???
Arturo
I still have the problem! What can I do?
Dates in json are converted into a different format format, so you should change into type date before you store them in the database.
For example use a beforeInsert hook with:
item.date = new Date(item.date);
@jonatandor35 Thank you for your answer. But it works with a problem: I send, for instance Oct 30 , 00:00 but it imports Oct 29, 07:00 PM. With 5 hours of difference. I should correct this in the hook?
@avillarg Are you sure it’s not a matter of time zone difference (i.e. the sender and the receiver are in different location and therefore the time is presented to each of them based on their time zone)?
And anyway if you have control over the sending format, I’d suggest to send it as a number. i.e. :
On the sender size before you stringify the JSON:
item.date = item.date.getTime();
//JSON.stringify(item) etc....
and then use the hook I posted.
@jonatandor35 Now i’m sending a number ( epoch format: Ex: 1604016000 or 1604448000) and in the hook I use: item.fechaApertura = new Date(item.fechaApertura). But nothing is imported. Do I have to convert this number before to use it in the Date function?