15

I want to add 30 days to current date and get in a format.

Im confused to add a 30 to a date and get new.

Its pure JS Solution needed.

Format : June 10, 2017

Sarath
  • 207
  • 1
  • 2
  • 7
  • 2
    Please always first use the Search box of this site (or even Google), as I typed `javascript add days` and found this duplicate right away. And if you need it formatted, just search for `javascript format date`. – Peter B Jun 29 '17 at 13:53
  • Thanks @PeterB, Its was a urgent one. – Sarath Jun 29 '17 at 14:08

3 Answers3

62
var date = new Date(); // Now
date.setDate(date.getDate() + 30); // Set now + 30 days as the new date
console.log(date);
Lennholm
  • 7,205
  • 1
  • 21
  • 30
0

Im assuming you are using datejs?

var newDate = Date.today().add(30).days();
Bola
  • 718
  • 1
  • 6
  • 20
  • Hey, you actually may be right. The questions tag suggests `datejs` so this is the answer. Although the tag probably wasn't intentional – wiktus239 Jul 23 '21 at 09:37
0

try following:

var yourDate = new Date();
var numberOfDaysToAdd = 30;
console.log(yourDate.setDate(yourDate.getDate() + numberOfDaysToAdd)); 
Murtuza Z
  • 5,639
  • 1
  • 28
  • 52