Hello guys am trying to calculated number yof days a user has been registered on my website using information obtained from my database.
I would also like to do calculation on #text16 the result should be #text multiplied by 40.
This my code:
import wixData from ‘wix-data’;
$w.onReady( function () {
$w(“#dataset3”).onReady( () => { let originalDate = itemData._createdtedDate; let todaysDate = new Date(); let timeDiff = todaysDate.getTime() - originalDate.getTime(); let timeConv = Math.ceil(timeDiff / (1000360024));
$w(“#dataset3”).onReady( () => {
{ if (timeConv > 0) {
$w("#text16").text = "1"
}
else
{ let daysLeft = timeConv;
$w(“#text16”).text = daysLeft.toString();
Hi,
You have some syntax and calculation errors, check out this code and modify it to match your site.
import wixData from 'wix-data';
$w.onReady(function () {
$w("#dataset3").onReady( () => {
let date1 = $w("#dataset3").getCurrentItem()._createdDate;
let date2 = new Date();
let timeDiff = Math.abs(date2.getTime() - date1.getTime());
let diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log(diffDays);// number of days
let text = diffDays * 40; // as you wrote in the description
$w("#text16").text = text;
});
.catch( (err) => {
console.log(err);
} );
}); // you had missing parentheses and brackets