How to Find out date (ex:10-10-2018) based on the time span or time period (like: 3 years 1 month)

Hey guys, ERPNext is awesome work. I really loved it and the support you are providing is excellent.I am bit experimenting with the ERPNext and its features. i wonder that can we calculate the date based on time period.

like i got two fields 1. time period.(in years) 2. date of delivery.
user gives input in 1st field like after 3 years . after saving he should be able to see what date it is after 3 years. like (today- month -2018).

Thanks in advance

Use, frappe.datetime.add_months(new Date(), no_of_months) .

Ref Custom Script

Hi Saurabh… thanks for helping. but im really gonna bug you more. i am really sorry for that. but can you please explain me with the example please… and is that new Date() a function. and where do i can find more about it? in the api?
and i want to calculate it on client side thats the challenge for me…

Hi,

This is a client side method.

Our method frappe.datetime.add_months(todays_date_object, total_no_of_months) takes two parameters,

First parameter is, new Date() is JavaScript’s date function, it will return today’s date object.

Second parameter is; number of months, in our case as we want date after three years so will pass 36 at second position, ie 3(years)*12(months_per_year).

so now our methods looks like , ie frappe.datetime.add_months(new Date(), 36) output is “2018-09-05”

No Documentation as such yet, but Login to erpnext and from browser console you can get other methods.

1 Like

Thank you very much Saurabh…

It worked… :smile: thank you @saurabh

Code is

cur_frm.cscript.custom_refresh = function(doc) {
delivery_date= frappe.datetime.add_months(new Date(), doc.delivery_period);
cur_frm.set_value(“delivery_date”, delivery_date);
}

where as delivery_date is field name.

thank you team ERPNext