www.webdeveloper.com
Results 1 to 5 of 5

Thread: how to add days to current date in javascript

  1. #1
    Join Date
    Jun 2007
    Posts
    22

    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*

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    var today = new Date();
    today.setDate(today.getDate() + numberOfDaysToAdd);
    Stephen

  3. #3
    Join Date
    Jun 2007
    Posts
    22
    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*

  4. #4
    Join Date
    May 2005
    Location
    Northern Indiana
    Posts
    597
    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.

  5. #5
    Join Date
    Apr 2008
    Posts
    1
    <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
  •  
HTML5 Development Center



Recent Articles