Date and time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samir

    #1

    Date and time

    Say I put a date and time for like this:
    Jun-15-04 21:52:06

    Here is the form I am using:
    <form>
    <p><input type="text" name="T1" size="20"><br>
    date</p>
    <p><input type="text" name="T2" size="20"><br>
    90 days from date</p>
    <p><input type="submit" value="Submit" name="B1"></p>
    </form>

    How could I get to show the date 90 days later to the exact date and time.
    I would enter the data in the first box and hit submit to show in the second
    box.

    TIA


  • Lee

    #2
    Re: Date and time

    Samir said:[color=blue]
    >
    >Say I put a date and time for like this:
    >Jun-15-04 21:52:06
    >
    >Here is the form I am using:
    ><form>
    > <p><input type="text" name="T1" size="20"><br>
    > date</p>
    > <p><input type="text" name="T2" size="20"><br>
    > 90 days from date</p>
    > <p><input type="submit" value="Submit" name="B1"></p>
    ></form>
    >
    >How could I get to show the date 90 days later to the exact date and time.
    >I would enter the data in the first box and hit submit to show in the second
    >box.[/color]

    If you're not going to be sending the data to your server,
    you shouldn't use a submit element. Use an input of type
    "button", instead.

    <input type="button"
    value="Submit"
    onclick="this.f orm.date2.value =plus90(this.fo rm.date1.value) ">

    "T1" and "T2" (and "B1") are pretty bad names for form fields.
    Why not at least "date1" and "date2"?

    As for what the function I've called plus90() should do,
    check the date manipulation links referenced in the FAQ:


    You may want to rethink the input format.
    It's a lot easier if the format is "Jun 15 2004 21:52:06".

    Comment

    • Evertjan.

      #3
      Re: Date and time

      Lee wrote on 19 aug 2004 in comp.lang.javas cript:
      [color=blue]
      > Samir said:[color=green]
      >>
      >>Say I put a date and time for like this:
      >>Jun-15-04 21:52:06[/color][/color]
      [color=blue]
      > You may want to rethink the input format.
      > It's a lot easier if the format is "Jun 15 2004 21:52:06".[/color]

      A lot??

      t = "Jun-15-04 21:52:06"

      t = t.replace(/-(\d\d) /," 20$1 ").replace(/-/g," ")

      [allows also last century as 19..]

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Date and time

        Lee <REM0VElbspamtr ap@cox.net> wrote:

        Your From address does not specify a mailbox which is a violation of
        Internet/Usenet standards and disregarding the Netiquette as well
        as most certainly a violation of the Acceptable Use Policy of your
        service provider.  You have been warned.

        <http://www.interhack.n et/pubs/munging-harmful/>
        [color=blue]
        > Samir said:[color=green]
        >> Say I put a date and time for like this:
        >> Jun-15-04 21:52:06
        >>
        >> Here is the form I am using:
        >> <form>
        >> <p><input type="text" name="T1" size="20"><br>
        >> date</p>
        >> <p><input type="text" name="T2" size="20"><br>
        >> 90 days from date</p>
        >> <p><input type="submit" value="Submit" name="B1"></p>
        >> </form>
        >>
        >> How could I get to show the date 90 days later to the exact date and
        >> time. I would enter the data in the first box and hit submit to show in
        >> the second box.[/color]
        >
        > If you're not going to be sending the data to your server,
        > you shouldn't use a submit element. Use an input of type
        > "button", instead.[/color]

        Wrong. Using a submit button may also be useful without a server, if it
        is used in an application using only client-side scripting and the required
        DOM access methods are for some reason not available or viable. Example:

        <http://pointedears.de/scripts/test/ObjectInspector/nightly/latest/index>

        It would be more correct to say that using a submit button is not viable
        if re-accessing or changing the container element's resource is undesired
        which is the case here.
        [color=blue]
        > You may want to rethink the input format.
        > It's a lot easier if the format is "Jun 15 2004 21:52:06".[/color]

        Why?


        PointedEars
        --
        Everyone thinks I'm psychotic, except for my friends deep inside the earth.

        Comment

        • Lee

          #5
          Re: Date and time

          Evertjan. said:[color=blue]
          >
          >Lee wrote on 19 aug 2004 in comp.lang.javas cript:
          >[color=green]
          >> Samir said:[color=darkred]
          >>>
          >>>Say I put a date and time for like this:
          >>>Jun-15-04 21:52:06[/color][/color]
          >[color=green]
          >> You may want to rethink the input format.
          >> It's a lot easier if the format is "Jun 15 2004 21:52:06".[/color]
          >
          >A lot??[/color]

          Yes: var firstDate=new Date("Jun 15 2004 21:52:06");

          Comment

          • Dr John Stockton

            #6
            Re: Date and time

            JRS: In article <cg169k02sid@dr n.newsguy.com>, dated Wed, 18 Aug 2004
            20:20:20, seen in news:comp.lang. javascript, Lee
            <REM0VElbspamtr ap@cox.net> posted :[color=blue]
            >Samir said:[color=green]
            >>
            >>Say I put a date and time for like this:
            >>Jun-15-04 21:52:06[/color][/color]
            [color=blue][color=green]
            >>How could I get to show the date 90 days later to the exact date and time.[/color][/color]
            [color=blue]
            >As for what the function I've called plus90() should do,
            >check the date manipulation links referenced in the FAQ:
            >http://www.jibbering.com/faq/
            >
            >You may want to rethink the input format.
            >It's a lot easier if the format is "Jun 15 2004 21:52:06".[/color]

            Samir is probably a foreigner (everybody is probably a foreigner on the
            Internet). Can one be sure that in all browsers the form "Jun" is
            recognised? AFAICS, ECMA is indecisive in such matters (ICBW); and not
            all software is compliant with applicable standards - some foreign
            software systems are configured with excessive localisation.

            Accordingly, I would suggest instead 2004/06/15 21:52:06 xxx
            where xxx is either absent, a well-known time zone indicator, or an
            offset from GMT. The form is as close to ISO 8601 as my browser will
            accept.

            Unless users are restricted to odd places like China, Hawaii, Guam, the
            ISS, Iceland, Morocco, and Ghana, etc., the OP needs to decide whether
            the 90 days are to be of real time or of user's civil time.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
            Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
            PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
            Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

            Comment

            • Samir

              #7
              Re: Date and time

              Okay here is my redited code

              <form>
              <p><input type="text" name="date1" size="20"><br>
              date</p>
              <p><input type="text" name="date2" size="20"><br>
              90 days from date</p>
              <p><input type="button" value="Submit" name="B1"
              onclick="this.f orm.date2.value =plus90(this.fo rm.date1.value) "></p>
              </form>

              I can't seem to know how to do this, I couldn't find the function in the
              page you have said. Can anyone else help me?
              <script language="javas cript">
              function plus90(){
              ??????????????? ??????????????? ?????
              }
              </script>

              "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
              news:cg169k02si d@drn.newsguy.c om...[color=blue]
              > Samir said:[color=green]
              > >
              > >Say I put a date and time for like this:
              > >Jun-15-04 21:52:06
              > >
              > >Here is the form I am using:
              > ><form>
              > > <p><input type="text" name="T1" size="20"><br>
              > > date</p>
              > > <p><input type="text" name="T2" size="20"><br>
              > > 90 days from date</p>
              > > <p><input type="submit" value="Submit" name="B1"></p>
              > ></form>
              > >
              > >How could I get to show the date 90 days later to the exact date and[/color][/color]
              time.[color=blue][color=green]
              > >I would enter the data in the first box and hit submit to show in the[/color][/color]
              second[color=blue][color=green]
              > >box.[/color]
              >
              > If you're not going to be sending the data to your server,
              > you shouldn't use a submit element. Use an input of type
              > "button", instead.
              >
              > <input type="button"
              > value="Submit"
              > onclick="this.f orm.date2.value =plus90(this.fo rm.date1.value) ">
              >
              > "T1" and "T2" (and "B1") are pretty bad names for form fields.
              > Why not at least "date1" and "date2"?
              >
              > As for what the function I've called plus90() should do,
              > check the date manipulation links referenced in the FAQ:
              > http://www.jibbering.com/faq/
              >
              > You may want to rethink the input format.
              > It's a lot easier if the format is "Jun 15 2004 21:52:06".
              >[/color]



              Comment

              • Evertjan.

                #8
                Re: Date and time

                Samir wrote on 19 aug 2004 in comp.lang.javas cript:[color=blue]
                > Okay here is my redited code
                >
                > <form>
                > <p><input type="text" name="date1" size="20"><br>
                > date</p>
                > <p><input type="text" name="date2" size="20"><br>
                > 90 days from date</p>
                > <p><input type="button" value="Submit" name="B1"
                > onclick="this.f orm.date2.value =plus90(this.fo rm.date1.value) "></p>
                > </form>
                >
                > I can't seem to know how to do this, I couldn't find the function in
                > the page you have said. Can anyone else help me?
                >[/color]

                <form>
                <input type="text" name="date1" size="20"><br>
                date (yyyy/mm/dd)<br><br>
                <input type="text" name="date2" size="20" readonly><br>
                90 days from date<br><br>
                <input type="button" value="Calculat e"
                onclick="plus90 (this);">
                </form>


                <script type="text/javascript">

                document.forms( 0).date1.value = dateToString(ne w Date())

                function dateToString(d) {
                return [d.getYear(),d.g etMonth()+1,d.g etDate()].join('/')
                }

                function plus90(x){
                d = new Date(x.form.dat e1.value)
                d = new Date(d.getYear( ),d.getMonth(), d.getDate()+90)
                x.form.date2.va lue = dateToString(d)
                }

                </script>

                --
                Evertjan.
                The Netherlands.
                (Please change the x'es to dots in my emailaddress)

                Comment

                • Michael Winter

                  #9
                  Re: Date and time

                  On 19 Aug 2004 19:39:10 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
                  wrote:

                  [snip]
                  [color=blue]
                  > function dateToString(d) {
                  > return [d.getYear(),d.g etMonth()+1,d.g etDate()].join('/')
                  > }
                  >
                  > function plus90(x){
                  > d = new Date(x.form.dat e1.value)
                  > d = new Date(d.getYear( ),d.getMonth(), d.getDate()+90)[/color]

                  Wouldn't

                  d = new Date(...);
                  d.setDate(d.get Date() + 90);

                  be simpler?

                  Also, getFullYear() is preferable to getYear().

                  Mike

                  --
                  Michael Winter
                  Replace ".invalid" with ".uk" to reply by e-mail.

                  Comment

                  • Evertjan.

                    #10
                    Re: Date and time

                    Michael Winter wrote on 19 aug 2004 in comp.lang.javas cript:[color=blue]
                    > Wouldn't
                    >
                    > d = new Date(...);
                    > d.setDate(d.get Date() + 90);
                    >
                    > be simpler?[/color]

                    Yes, more concise, but perhaps not as clear to the OP.

                    [color=blue]
                    > Also, getFullYear() is preferable to getYear().[/color]

                    Why, in this case?


                    --
                    Evertjan.
                    The Netherlands.
                    (Please change the x'es to dots in my emailaddress)

                    Comment

                    • Samir

                      #11
                      Re: Date and time

                      Thanks!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!

                      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                      news:Xns954ADC5 205F01eejj99@19 4.109.133.29...[color=blue]
                      > Samir wrote on 19 aug 2004 in comp.lang.javas cript:[color=green]
                      > > Okay here is my redited code
                      > >
                      > > <form>
                      > > <p><input type="text" name="date1" size="20"><br>
                      > > date</p>
                      > > <p><input type="text" name="date2" size="20"><br>
                      > > 90 days from date</p>
                      > > <p><input type="button" value="Submit" name="B1"
                      > > onclick="this.f orm.date2.value =plus90(this.fo rm.date1.value) "></p>
                      > > </form>
                      > >
                      > > I can't seem to know how to do this, I couldn't find the function in
                      > > the page you have said. Can anyone else help me?
                      > >[/color]
                      >
                      > <form>
                      > <input type="text" name="date1" size="20"><br>
                      > date (yyyy/mm/dd)<br><br>
                      > <input type="text" name="date2" size="20" readonly><br>
                      > 90 days from date<br><br>
                      > <input type="button" value="Calculat e"
                      > onclick="plus90 (this);">
                      > </form>
                      >
                      >
                      > <script type="text/javascript">
                      >
                      > document.forms( 0).date1.value = dateToString(ne w Date())
                      >
                      > function dateToString(d) {
                      > return [d.getYear(),d.g etMonth()+1,d.g etDate()].join('/')
                      > }
                      >
                      > function plus90(x){
                      > d = new Date(x.form.dat e1.value)
                      > d = new Date(d.getYear( ),d.getMonth(), d.getDate()+90)
                      > x.form.date2.va lue = dateToString(d)
                      > }
                      >
                      > </script>
                      >
                      > --
                      > Evertjan.
                      > The Netherlands.
                      > (Please change the x'es to dots in my emailaddress)[/color]



                      Comment

                      • Michael Winter

                        #12
                        Re: Date and time

                        On 19 Aug 2004 19:58:27 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
                        wrote:
                        [color=blue]
                        > Michael Winter wrote on 19 aug 2004 in comp.lang.javas cript:[color=green]
                        >> Wouldn't
                        >>
                        >> d = new Date(...);
                        >> d.setDate(d.get Date() + 90);
                        >>
                        >> be simpler?[/color]
                        >
                        > Yes, more concise, but perhaps not as clear to the OP.[/color]

                        I suppose. However I'm sure the OP would see "<something > + 90" as
                        increasing the days as originally requested.
                        [color=blue][color=green]
                        >> Also, getFullYear() is preferable to getYear().[/color]
                        >
                        > Why, in this case?[/color]

                        03/04/05

                        For the usual reason: what does that date represent?

                        That and the OP specifies the format on the page as yyyy/mm/dd. I think it
                        would be a good idea to stick with that.

                        Mike

                        --
                        Michael Winter
                        Replace ".invalid" with ".uk" to reply by e-mail.

                        Comment

                        • Evertjan.

                          #13
                          Re: Date and time

                          Michael Winter wrote on 19 aug 2004 in comp.lang.javas cript:
                          [color=blue]
                          > 03/04/05
                          >
                          > For the usual reason: what does that date represent?[/color]

                          You are right, Michael.
                          I did not test for pre 1900-1999 years.
                          [color=blue]
                          > That and the OP specifies the format on the page as yyyy/mm/dd. I
                          > think it would be a good idea to stick with that.[/color]

                          You are wrong,
                          he did not specify yyyy/mm/dd,
                          I did.
                          ;-}

                          --
                          Evertjan.
                          The Netherlands.
                          (Please change the x'es to dots in my emailaddress)

                          Comment

                          • Samir

                            #14
                            Re: Date and time

                            How would the function work if I were to test for pre 1900-1999 years????


                            "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                            news:Xns954AF1A 8DF6Eeejj99@194 .109.133.29...[color=blue]
                            > Michael Winter wrote on 19 aug 2004 in comp.lang.javas cript:
                            >[color=green]
                            > > 03/04/05
                            > >
                            > > For the usual reason: what does that date represent?[/color]
                            >
                            > You are right, Michael.
                            > I did not test for pre 1900-1999 years.
                            >[color=green]
                            > > That and the OP specifies the format on the page as yyyy/mm/dd. I
                            > > think it would be a good idea to stick with that.[/color]
                            >
                            > You are wrong,
                            > he did not specify yyyy/mm/dd,
                            > I did.
                            > ;-}
                            >
                            > --
                            > Evertjan.
                            > The Netherlands.
                            > (Please change the x'es to dots in my emailaddress)[/color]



                            Comment

                            • Michael Winter

                              #15
                              [OT] Re: Date and time

                              On 19 Aug 2004 21:45:01 GMT, Evertjan. <exjxw.hannivoo rt@interxnl.net >
                              wrote:

                              [snip]
                              [color=blue]
                              > You are right, Michael.[/color]

                              Mike will do just fine. :)

                              [snip]
                              [color=blue]
                              > You are wrong,
                              > he did not specify yyyy/mm/dd,
                              > I did.
                              > ;-}[/color]

                              Ermm. Yes, I knew that. (D'oh!)

                              Mike

                              --
                              Michael Winter
                              Replace ".invalid" with ".uk" to reply by e-mail.

                              Comment

                              Working...