Use JS to add and subtract dates and days

Source: Internet
Author: User

To add or subtract days from a date, just call the setdate () function of the Date object, as follows: (easy to use)

function Adddate (date,days) {//date plus minus days
var d=new date (date);
D.setdate (D.getdate () +days);
var m=d.getmonth () +1;
return d.getfullyear () + '-' +m+ '-' +d.getdate ();


Where the date parameter is to be added and minus the day, the days parameter is to be added and minus the number, if the forward count is passed in negative numbers, the next count is passed in positive numbers, if the month is to be added and minus, call Setmonth () and getmonth () on it, It is important to note that the returned month is calculated starting at 0, which means that the returned month is one months less than the actual month, so add 1 accordingly.

Use JS to add and subtract dates and days

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.