need to add 15 days to date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cory bowden
    New Member
    • Feb 2011
    • 4

    need to add 15 days to date

    I have tried everyway that I can think of to get this code to add 15 days with out the funky date happening and thus far no luck.

    Code:
    <script type="text/javascript">
    <!--
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate()
    var year = currentTime.getFullYear();
    document.write(month + "/" + day + "/" + year)
    //-->
    </script>
    Last edited by Dormilich; Feb 23 '11, 10:15 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    convert the date into a UNIX Timestamp (JS uses milliseconds) add 15 days in milliseconds, instantiate new Date object with this.

    Comment

    • cory bowden
      New Member
      • Feb 2011
      • 4

      #3
      im new at this so i have no clue of how to do that. I am learning but as everything else takes time.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        then you definitely will need a solid reference page. I use MDC (Mozilla Developer Center). there are listed all methods and properties as well as usage examples.

        (entry for Date)

        by using that you should be able to code what I described in words.

        Comment

        • cory bowden
          New Member
          • Feb 2011
          • 4

          #5
          Even more confused now. I see what you are taking about with the milliseconds but am completely confused on how to swith over what i have already to that.
          Code:
          new Date()
          Today = new Date();
          var ms;
          var currentTime = new Date();
          document.write(currentTime)

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            An even simpler way:

            get the current day (getDate)
            then set the day to that + 15 using setDate

            Comment

            • cory bowden
              New Member
              • Feb 2011
              • 4

              #7
              I appriciate your help but this is getting me nowhere, as i have said I have done everything that I can think of and as much as I appriciate the point in the right direction when someone is already frustrated at the code that should be fairly simple for over a week and still cant get it to work properly it would be a great help and relief to see a little code that can help them get to where they need to be not just look here and look there. we come on this forum seeking help not to be told to look showhere else.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                From your original code, after line 6, add this:
                Code:
                currentTime.setDate(day+15);
                You will then need to recalculate the day/month/year values to get the new date to display (the date object will now hold the new date).
                Last edited by acoder; Feb 24 '11, 11:13 AM.

                Comment

                Working...