Working with a Date...

Discussion in 'Programming' started by dweekley, Jan 19, 2011.

  1. #1
    I am new to working with dates. I am trying to get this script to work. I am trying to get the T1.value to be increased by 7 days based on the variable id.

    <script type="text/javascript">
    function isdate()
    {
    with (document.forms[0])
    {
    var id = chosendate.value;

    T29.value = id
    T1.value = id.setDate(id.getDate()+7)
    }
    }
    </script>

    Thanks for any assistance.
    David
     
    dweekley, Jan 19, 2011 IP
  2. xtmx

    xtmx Active Member

    Messages:
    359
    Likes Received:
    12
    Best Answers:
    4
    Trophy Points:
    88
    #2
    If chosendate is displayed as "m/d/y", try

    <script type="text/javascript">
    function isdate()
    {
    with (document.forms[0])
    {
    var tmp = chosendate.value.split("/");

    var id = new Date(tmp[2].valueOf(), tmp[0].valueOf(), tmp[1].valueOf());

    T29.value = id
    T1.value = id.setDate(id.getDate()+7)
    }
    }
    </script>
     
    xtmx, Jan 19, 2011 IP
  3. dweekley

    dweekley Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello, thanks for the response. However, I am getting an Object doesn't support this property or method

    David
     
    dweekley, Jan 20, 2011 IP
  4. dweekley

    dweekley Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello, I believe I have this script working...but I do not know how to format T1 back to mm/dd/yyyy

    <script type="text/javascript">
    function isdate()
    {
    with (document.forms[0])
    {
    var chdate = new Date(chosendate.value);
    var dd = chdate.getDate();
    var mm = chdate.getMonth()+1;//January is 0!
    var yyyy = chdate.getFullYear();

    var caldate = mm+'/'+dd+'/'+yyyy;

    T29.value = caldate
    T1.value = chdate.setDate(chdate.getDate()+7);
    }
    }
    </script>

    David
     
    dweekley, Jan 20, 2011 IP
  5. dweekley

    dweekley Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hello, the script below is about as far as I can go...

    <script type="text/javascript">
    function isdate()
    {
    with (document.forms[0])
    {
    var chdate = new Date(chosendate.value);

    T29.value = chosendate.value;
    T1.value = (chdate.getMonth()+1)+'/'+chdate.setDate(chdate.getDate()+7)+'/'+chdate.getFullYear()
    T2.value = (chdate.getMonth()+1)+'/'+chdate.setDate(chdate.getDate()+14)+'/'+chdate.getFullYear()
    T3.value = (chdate.getMonth()+1)+'/'+chdate.setDate(chdate.getDate()+21)+'/'+chdate.getFullYear()
    T4.value = (chdate.getMonth()+1)+'/'+chdate.setDate(chdate.getDate()+28)+'/'+chdate.getFullYear()

    }
    }
    </script>

    for the dd I am getting a result like...1/1296190800000/2011

    Any help would be appreciated.

    Thanks
    David
     
    dweekley, Jan 21, 2011 IP