Hello, all! I would like to use an afterQuery Hook to calculate 30 days from the datePurchased.
Database Name:
projects
Date Purchased:
Field Key: datePurchased
Custom Form Field: Date & Time User Input Date Picker Element
Database Field Type: Date & Time
Expiration Date:
Field Key: expirationDate
Custom Form Field: Text (but I am willing to change it if necessary)
Database Field Type: Text (but I am willing to change it if necessary)
Could you help?
SOLUTION
let startdd = ('0' + item.datePurchased.getDate()).slice(-2);
let startmm = ('0' + (item.datePurchased.getMonth() + 1)).slice(-2);
let startyy = item.datePurchased.getFullYear().toString().substr(2, 2);
let starttt = item.datePurchased.getTime();
//86400000 milliseconds in a day
let timeThirtyDaysHence = starttt + (30 * 86400000);
let thirtyDaysHence = new Date(timeThirtyDaysHence);
let validityPeriod = thirtyDaysHence;
item.expirationDate = validityPeriod;
return item;
}
Thanks, @anthonyb ! That helped!
Hi Juanita,
There was a similar request involving date arithmetic a few days ago. See if this doesn't give you a clear idea of how to proceed.
https://www.wix.com/corvid/forum/community-discussion/30-days-between-todays-date-and-a-date-from-an-input-then-carry-out-a-function