Hi There,
I been trying to upload JSON data in database using Import option given in the article. Its working perfectly but the date field is uploading as Text. Am not sure how to convert it in Date. Have inserted hooks as well but it failed or I dont know whether I have done it right. Please help me out
export function importbutton_click(event) {
const items = JSON.parse($w(“#textBox”).value);
const collection = $w(“#collectionInput”).value;
items.forEach( (item) => {
wixData.insert(collection, item)
.then( (results) => {
let item = results;
console.log(`Added item: ${JSON.stringify(results)}`);
} )
.catch( (err) => {
console.log(err);
} );
} );
$w(“#textBox”).value = “”;
}
//---- Hooks script
export function LM_Attendance_beforeInsert(item, context) {
const at_date_hk = item.at_date;
const at_in_hk = item.at_in;
const at_out_hk = item.at_out;
var dd_date = at_date_hk.getDate();
var yyyy_date = at_date_hk.getFullYear();
var mm_date = at_date_hk.getMonth() + 1; //January is 0!
var days_date = at_date_hk.getDay();
var hours_date = at_date_hk.getHours();
var minutes_date = at_date_hk.getMinutes();
var sec_date = at_date_hk.getSeconds();
var msec_date = at_date_hk.getMilliseconds();
var dd_in = at_in_hk.getDate();
var mm_in = at_in_hk.getMonth()+1; //January is 0!
var yyyy_in = at_in_hk.getFullYear();
var dd_out = at_out_hk.getDate();
var mm_out = at_out_hk.getMonth()+1; //January is 0!
var yyyy_out = at_out_hk.getFullYear();
var datNewDate = new Date(yyyy_date, mm_date, days_date, hours_date, minutes_date, sec_date, msec_date) ;
item.dateJoined = datNewDate;
return item;
}
}