I am using below code for getting difference of two dates by generating today’s date separately in form. Problem is frappe.datetime.nowdate() generates date format as YYYY-MM-DD and hence below code doesn’t give any result. I want to convert date format in below code to DD-MM-YYYY for the “form_date” field
frappe.ui.form.on(“Installation Note”, “refresh”, function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frm.set_value(“form_date”, frappe.datetime.nowdate());
frappe.model.set_value(cdt, cdn, “diff_install”, frappe.datetime.get_day_diff( d.form_date, d.Installation_date));
refresh_field(“diff_install”);
});
To format date, you can use e.g.:
frappe.datetime.now().format(“DD-MM-YYYY”)
or:
moment(some_date).format(“DD-MM-YYYY”)
It doesn’t work.
Still problem persists. date difference is not getting calculated.
Is it because on field is having format date and other is data(from custom script)?
It looks that frappe.datetime.get_day_diff() expects both dates in format set in system settings. For my company it’s yyyy-mm-dd.
So you should format both dates to match your settings.
If frappe.datetime.nowdate() gives you date in format YYYY-MM-DD, it’s probably your setting (not DD-MM-YYYY). So for frappe.datetime.get_day_diff() both dates should be formatted as YYYY-MM-DD, not as DD-MM-YYYY, as you requested.
Please check if d.Installation_date is correct:
- name with capital letter I?
- display it with console.log(), or alert() to check the value, so you will know how to format it.