How to subtract date?

do you want to get different day between post date and due date? or 2018-02-06 subtract 2 days, then 2018-02-04 ?

yes i need to compute how many days between posting date and due date.

frappe.datetime.get_diff(end_date, start_date); // return number of days

frappe.ui.form.on(“Child Doctype”, {
due_date: function(frm, cdt, cdn) {
var child = locals[cdt][cdn];
var doc = frm.doc;
var diff_day = frappe.datetime.get_diff(child.due_date, doc.posting_date);
}
});

hi! @magic-overflow thanks for your response.

i create another field to show the number of days between posting date and due date. and the name of field is

no_of_days_fr_delivery

ill try your code but it doesnt work

Hi Denmark_Del_Puso

If you trying to get how many days between two days in a period like from 1 Jan 2018 to 1 Feb 2018. If you need only the Working Days they magic-overflow script is going to work. Here is a good ref to date functions

frappe.ui.form.on("Child Doctype", {
    due_date: function(frm, cdt, cdn) {
        var child = locals[cdt][cdn];
        var doc = frm.doc;
        var diff_day = frappe.datetime.get_diff(child.due_date, doc.posting_date);
        frappe.model.set_value(child.doctype, child.name, "no_of_days_fr_delivery", diff_day);
    }
});

hi! @magic-overflow ill try your code but still the same not working.

my doctype this looks like. not loading

can you print screen your custom script and share error in your console?
If you copy and paste, it may cause the error with single quote and double quote.

@magic-overflow

You have wrong double quote, you can retype it again or try code below.

frappe.ui.form.on("Payment Entry Reference", {
    due_date: function(frm, cdt, cdn) {
        var child = locals[cdt][cdn];
        var doc = frm.doc;
        var diff_day = frappe.datetime.get_diff(child.due_date, doc.posting_date);
        frappe.model.set_value(child.doctype, child.name, "no_of_days_fr_delivery", diff_day);
        //edit
        refresh_field("no_of_days_fr_delivery");
    }
});

hi @magic-overflow ill try again still the same. empty didnt view.

please find my updated code above.

stil the same.

Due Date get from Sales Invoice DR-00001?

I’m afraid event on due date didn’t fire. You can set on Name.
I assume your fieldname Name is name and due date get from selected Name.

frappe.ui.form.on("Payment Entry Reference", {
    name: function(frm, cdt, cdn) {
        var child = locals[cdt][cdn];
        var doc = frm.doc;
        var diff_day = frappe.datetime.get_diff(child.due_date, doc.posting_date);
        frappe.model.set_value(child.doctype, child.name, "no_of_days_fr_delivery", diff_day);
        console.log(diff_day);
        //edit
        refresh_field("no_of_days_fr_delivery");
    }
});

yes my due date will get into sales invoice.

this is under of payment entry

and this is two fields under of child table named “Payment Entry Reference”

Can you try code below and check it your browser console?

 frappe.ui.form.on("Payment Entry Reference", {
        reference_name: function(frm, cdt, cdn) {
            var child = locals[cdt][cdn];
            var doc = frm.doc;
            var diff_day = frappe.datetime.get_diff(child.due_date, doc.posting_date);
            frappe.model.set_value(child.doctype, child.name, "no_of_days_fr_delivery", diff_day);
            console.log(diff_day);
            //edit
            refresh_field("no_of_days_fr_delivery");
        }
    });

yes ill try but cant get the result

is there any message in browser console?

no message but the result like this when i save.