I would like to get the difference in _createdDate and _updatedDate . This value should be multiplied by 10. Any help, full code will be appreciated.
Hi,
First, transform the date fields values(will be strings) to Date objects, check out this documentation.
Once you have two date objects you can simply subtract them to get the difference in milliseconds.
Good luck,
Or
Hi,
_createdDate and _updatedDate are a Date object, so they familiar with the JS date functions such as getTime(), getSeconds() etc.
If you wish the ‘datediffereance’ field will be update automatically after the item as been updated you can add a hook function that will do this calculation and insert the result to the ‘datediffereance’ field.
View this links for more info about hooks:
https://support.wix.com/en/article/corvid-about-data-hooks
https://www.wix.com/corvid/reference/wix-data.Hooks.html
Best,
Sapir
Can you please give me an example of code o use? Am still learning how to use wix code
Here is my code, Or
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(“#dataset4”).onReady(() => {
let date1 = itemData._createdDate;
let date2 = itemData._updatedDate; // today
let timeDiff = Math.abs(date2.getTime() - date1.getTime());
let diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
$w(“#dataset4”).onReady(() => {
{
if (diffDays < 1) {
$w(“#text10”).text = “40”
} **else** {
let daysLeft = 40 * diffDays;
$w(“#text10”).text = daysLeft.toString()
}
}
});
});
});
There is an error at itemDate