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;
}