how to code to calculate the date based on the user select date and the duration?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wish
    New Member
    • May 2007
    • 65

    how to code to calculate the date based on the user select date and the duration?

    Dear all;

    Can someone guide me how to code out the javascript to calculate the estimate date based on the user selected date and the how long the duration in term of week.

    eg. 19/9/2007 is select by user
    1 weeks is duration also select by user

    ans: 26/9/2007

    Thanks for ur help.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by wish
    Dear all;

    Can someone guide me how to code out the javascript to calculate the estimate date based on the user selected date and the how long the duration in term of week.

    eg. 19/9/2007 is select by user
    1 weeks is duration also select by user

    ans: 26/9/2007

    Thanks for ur help.
    Good Idea! :)
    But post some code here you have already.
    Then we will help you to achieve your Goal and I promise you, you will really enjoy with us while solving a problem.

    Kind regards,
    Dmjpro.

    Comment

    • wish
      New Member
      • May 2007
      • 65

      #3
      I'm not expert in javascript and never learn before when in college..Then how do i start the script?

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by wish
        I'm not expert in javascript and never learn before when in college..Then how do i start the script?
        Ok!.
        Try this Code.

        [code=html]
        <html>
        <head>
        <title>Simple Date Test</title>
        <script language = "JavaScript ">
        //Paste the JavaScript function here.
        </script>
        </head>
        <body>
        <input type = "text" id = "date">
        <input type = "text" id = "duration">
        <input type = "button" onclick = "getDate()" value = " Get Value ">
        <input type= "text" readonly id = "op">
        </body>
        </html>
        [/code]

        [code=javascript]
        function getDate()
        {
        try{
        var _date = document.getEle mentById("date" ).value, _duration = document.getEle mentById("durat ion").value;
        var date_obj = new Date(); /*Assusmed that your date pattern is dd/mm/yyyy*/
        date_obj.setFul lYear(_date.sub string(_date.la stIndexOf('/')+1)
        ,_date.substrin g(_date.indexOf ('/')+1,_date.last IndexOf('/'))-1
        ,_date.substrin g(0,_date.index Of('/')));
        date_obj.setDat e(date_obj.getD ate()+parseInt( _duration));
        //alert(date_obj. getDate());
        document.getEle mentById('op'). value = date_obj.getDat e()+'/'+(date_obj.get Month()+1)+'/'+date_obj.getF ullYear();
        }catch(e){alert (e.description) ;}
        }
        [/code]

        Good Luck.

        Kind regards,
        Dmjpro.

        Comment

        Working...