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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Date Script Problem

    Im trying to get this date script to work but display the DAY at 7 days in the future. So if today is 05-01-06 I want the day to show 05-07-06. Here is the simple code im using.

    <script type="text/javascript">

    var mydate= new Date()
    var theyear=mydate.getFullYear()
    var themonth=mydate.getMonth()+1
    var thetoday=mydate.getDate()

    document.write("Today's date is: ")
    document.write(theyear+"/"+themonth+"/"+thetoday)

    </script>

    I thought I could just change var thetoday=mydate.getDate() and just add +7 to make it var thetoday=mydate.getDate()+7

    But for some reason like today is 05-25-06 and the script calculates the date as 05-32-06 when i add the 7 days. Is there a way to get this to automatically go to the next month?

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    var d = new Date();

    d.setDate(d.getDate()+7);

    will get you what you want.

    getDate() just returns an integer. when you add 7 to the integer, you get the mathematically correct answer. 25 + 7 shouldn't equal 1.

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for the reply, im sorry to ask, what would be the format to put that fix into script? I still new and unsure. Could you paste what you replied i nto the script i showed u? Hope this isnt a bother to u.

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Don't code much?

    Code:
    <script type="text/javascript">
    
    var mydate= new Date();
    mydate.setDate(mydate.getDate() + 7);
    var theyear=mydate.getFullYear()
    var themonth=mydate.getMonth()+1
    var thetoday=mydate.getDate()
    
    document.write("Today's date is: ")
    document.write(theyear+"/"+themonth+"/"+thetoday)
    
    </script>


  •  

    Posting Permissions

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