/    Sign up×
Community /Pin to ProfileBookmark

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*

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@felgallJun 20.2007 — var today = new Date();

today.setDate(today.getDate() + numberOfDaysToAdd);
Copy linkTweet thisAlerts:
@msg2ajayauthorJun 20.2007 — 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*
Copy linkTweet thisAlerts:
@Tweak4Jun 20.2007 — 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.
Copy linkTweet thisAlerts:
@udkadamApr 02.2008 — <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
×

Success!

Help @msg2ajay spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...