Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 264
Jeny Avatar asked Jun 30 '26 08:06

Jeny


2 Answers

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!!!

like image 140
David Conde Avatar answered Jul 02 '26 22:07

David Conde


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

Tested on jsFiddle

like image 26
Anurag Uniyal Avatar answered Jul 02 '26 20:07

Anurag Uniyal