Jeny
Jeny

Reputation: 23

what is the date after 30days from current date using javascript

How can I find the date 30 days after the current day? here 30 is the fixed value. how can i pass the dynamic value to this function..

days = document.getElementById('day').value;
var d = new Date();
d.setDate(d.getDate() + days);

it is not working..it gives wrong answer

Upvotes: 2

Views: 19147

Answers (4)

David Conde
David Conde

Reputation: 4637

You can access the time in Javascript using the Date class. Try this:

var time = new Date();
time.setDate(time.getDate()+30);
alert(time);

EDIT Just added a test jsFiddle here in case somebody wants to test it.

Sorry I forgot the adding!!!

Upvotes: 17

Anurag Uniyal
Anurag Uniyal

Reputation: 88757

var d = new Date();
d.setDate(d.getDate()+30);
alert(d)

Tested on jsFiddle

Upvotes: 6

Pier Luigi
Pier Luigi

Reputation: 7871

var d = new Date();
d.setDate(d.getDate() + 30);

Upvotes: 3

David K.
David K.

Reputation: 6361

var thirty_days_from_now = new Date((new Date()).getTime() + 30*24*60*60*1000)

Upvotes: 4

Related Questions