Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2004
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help adding no. of days to specific date

    hello there,
    I am facing a problem with add no. of days to date,
    All the material that I found on the internet is concern with the current date whlie I want to calculate reultant date value after adding no. of days to any given date(not current).

    I am using this script:
    <script language="JavaScript"><!--
    function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
    }

    alert(addDays(new Date(),10));
    //--></script>


    but the problem is the script add no. of days to current date,
    I will really apreciate any help ,
    thank you

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Using your original function, you can pass a date other than the current date:

    alert(addDays(new Date("7/16/2004"),10));
    alert(addDays(new Date(2004, 8, 17),10));

    But your function can be simplified like this:
    Code:
    function addDays(myDate, days){
       myDate.setDate(myDate.getDate()+days);
       return myDate;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •