How do I add a date to DateTime?

Asked 2 years ago, Updated 2 years ago, 49 views

I want to add a date to the current DateTime in JavaScript, what should I do? Is there a function that JavaScript uses like AddDay on the dot net?

javascript date

2022-09-21 19:33

1 Answers

Well, I think you can make it like this and use it.

Date.prototype.addDays = function(days)
{
    var dat = new Date(this.valueOf());
    dat.setDate(dat.getDate() + days);
    return dat;
}

var dat = new Date();

alert(dat.addDays(5))


2022-09-21 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.