Hi,
I am trying to calculate Days to expire based on fields end_date and todays date.
I want the counter to display days left to expire.
I am using the following code
frappe.ui.form.on('bid_proposals', {
refresh: function(frm) {
calculate_days_expiring_in(frm);
},
end_date: function(frm) {
calculate_days_expiring_in(frm);
}
});
function calculate_days_expiring_in(frm) {
if (frm.doc.end_date) {
let endDate = new Date(frm.doc.end_date);
endDate.setHours(0, 0, 0, 0);
let today = new Date();
today.setHours(0, 0, 0, 0);
let diffTime = endDate - today;
let diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
frm.set_value('expires_in', diffDays);
}
}
Help is appreciated.
Thanks