Custom Script for Adding Number of Months to Date

Hi Everyone,

I have an issue, in which I need to calculate the “End Date” based on the “From Date” + “Contract Period”.
End Date = From Date + (Numer of Month in “Contract Period”)

Contract Period is Int Field


Thank you in advance

Hi @ERP_Implementer1,

Please apply it:

cur_frm.cscript.contract_period = function(doc, cdt, cd)
    cur_frm.set_value("end_date", frappe.datetime.add_months(doc.from_date, doc.contract_period));

Then check it.

Thank You!


frappe.datetime.add_days(date, days); // add n days to a date
frappe.datetime.add_months(date, months); // add n months to a date
frappe.datetime.month_end(date); // returns the first day from the month of the given date
frappe.datetime.month_start(date); // returns the last day from the month of the given date
frappe.datetime.get_day_diff(begin, end); // returns the days between 2 dates

1 Like

Thank you for your helping

it’s work with me when I add frm

cur_frm.cscript.contract_period = function(doc, cdt, cd)
frm.set_value(“end_date”, frappe.datetime.add_months(frm.doc.from_date, frm.doc.contract_period));