how to add days to current date in javascript
hi,
Is there any functions to add some number of days to the present date in the javascript......
THX & RGDS,
AJAY*
var today = new Date();
today.setDate(today.getDate() + numberOfDaysToAdd);
Stephen
hello stephen,
i have used the function but it is not returning the exact format. i hav used as below....
<script type="text/javascript">
var today = new Date();
document.write("days"+today.setDate(today.getDate()));
</script>
thx & rgds,
Ajay*
What format are you attempting to display?
The code you posted isn't going to do much. today.setDate(today.getDate()) should just return the current date, and by tacking "days" to the front like you did, it will literally return the word "days" in front of some garbled mess, since setDate() doesn't return a "friendly" date format.
<script language="JavaScript"><!--
function addDays(myDate,days) {
return new Date(myDate.getTime() + days*24*60*60*1000);
}
alert(addDays(new Date(),-100));
//--></script>
=Uday Kadam
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks