I have a piece of code to find the next month of the given date.
var d = new Date('2018-03-31');
dt = new Date(d.setMonth(d.getMonth() + 1));
document.getElementById("demo").innerHTML = dt;
But i'm wondering what is wrong here since it adds one month to March & gives May instead of April?
DEMO:
var d = new Date('2018-03-31');
dt = new Date(d.setMonth(d.getMonth() + 1));
document.getElementById("demo").innerHTML = dt;
<p id="demo"></p>
Use
setMonth(month, day)
d.setMonth(d.getMonth() + 1, 1); where day as 1st day of next month
Only if you are interested in Month part
var d = new Date('2018-03-31');
d.setMonth(d.getMonth() + 1, 1);
dt = new Date(d);
document.getElementById("demo").innerHTML = dt;
<p id="demo"></p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With