gooday to all… can you help me to solve my problem to automaticaly compute the number of days in custom script… tnx in advance
const date1 = new Date('7/13/2010');
const date2 = new Date('12/15/2010');
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffDays + " days");
you can use set_value instead of console.
thank you for your response can you please teach me step by step in custom script…thank you very much
you can use this code.
can you give me example sir …thankyou
frappe.ui.form.on(‘Voucher’, {
refresh: function(frm) {
const date1 = new Date(‘2010/12/05’);
const date2 = new Date(‘2010/10/10’);
const diffTime = Math.abs(date2 - date1);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffDays + " days");
frm.set_value(‘days’,diffDays);
}
});
instead of new Date(f_date
) you replace it with frm.doc.f_date
still error sir
dont use new Date
only frm.doc.f_date
still error sir
check documentation
i edited this script based on your doctype fields info, you can test
frappe.ui.form.on("Calc Date Diff", {
t_date: function(frm) {
if(frm.doc.f_date && frm.doc.t_date) {
var diffDays = Math.round(Math.abs(( (new Date(frm.doc.t_date) - new Date(frm.doc.f_date)) / (24 * 60 * 60 * 1000))))
frm.doc.diff_date = diffDays;
console.log(diffDays)
frm.refresh_fields()
}
}
})
thank you sir it’s working…
According to the old dating system, dates before the birth of Christ are counted backward and the letters BC (Before Christ) are added at their end . And for dates after the birth of Christ, AD is added. But in the new system, we use BCE and CE instead of BC and AD. For more detail see https://discuss.frappe.io/t/date-computaion/86970/15-apkbikI hope your question is solved
Thanks!