Any way to calculate 4 exact months after a date obtained from a string, for example "17/12/2017"?
Thanks in advance!
Any way to calculate 4 exact months after a date obtained from a string, for example "17/12/2017"?
Thanks in advance!
You have two problems:
Transform a string into a String
For your example, you could use something like this. Simple and specific. If you want something more generic you should go to some kind of solution by library.
var strDate = "17/12/2017";
var dateParts = strDate.split("/");
var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
Add months to a date
Here is an example that adds three months to the date January 31, 2009
var jan312009 = new Date(2009, 0, 31);
var eightMonthsFromJan312009 = jan312009.setMonth(jan312009.getMonth()+3);
Greetings