Last post Jul 26, 2019 02:30 AM by Yang Shen
Jul 25, 2019 08:56 AMemail@example.com|LINK
i have this date i want to add year by 60 number and get error calculation
<input type="text" id="date_of_birth" value="2019-01-01">
<input type="text" id=retiredate>
var d = new Date();
d.setMonth(d.getMonth() - 1);
d.setFullYear(d.getFullYear() + 60)
d.setHours(0, 0, 0);
i get this retire date 2079-06-25 which is error must be 2079-01-01
Jul 25, 2019 09:21 AM|PatriceSc|LINK
So it seems you want to force as well both the day and month ie :
d.setDate(1); // want to force 1st ?
d.setMonth(0); // want to force January ?
d.setFullYear(d.getFullYear() + 60);
Edit: or building the date you want rather than changing values : var d = new Date(new Date().getFullYear()+60,0);
For now the problem is that you don't do anything with the day and you decrease the month by 1 when it seems you want January 1st ?
Jul 25, 2019 09:33 AMfirstname.lastname@example.org|LINK
i want to calculate retirement date
Jul 25, 2019 10:46 AM|PatriceSc|LINK
Ok and ? The js above should give the result you asked for. If this is not what you actually want tell us more.
Jul 26, 2019 02:30 AM|Yang Shen|LINK
The d.getMonth() in your js will get the month of today(2019.7.25).
First, you need to assign a value to d. Please refer:
var d = new Date(document.getElementById('date_of_birth').value);
Then, change the setMonth method to: