date functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul J. Ettl

    date functions

    Two questions:

    I use

    var date1 = new Date();

    to get todays date. But how can I get yesterdays date?

    Furthermore I use

    var ydat = date1.getYear() ;
    var mdat = date1.getMonth( )+1;
    var hdat = "0"+date1.getDa te();
    var ddat = hdat.substr(hta g.length-2);
    var datum=ydat+"-0"+mdat+"-"+ddat;

    to get a string like 2004-06-01

    Is there a easier way to format the date?



    Paul Ettl





  • Evertjan.

    #2
    Re: date functions

    Paul J. Ettl wrote on 01 jun 2004 in comp.lang.javas cript:
    [color=blue]
    > to get todays date. But how can I get yesterdays date?[/color]

    Forgetting summer time changes this gives you same time 1 day earlier:

    var D = new Date()
    D.setDate(D.get Date()-1)

    alert(D)
    [color=blue]
    > Is there a easier way to format the date?[/color]


    function LZ(x) { return (x<0||x>=10?"": "0") + x }
    var D = new Date() ;
    D = D.getFullYear() +'-'+LZ(D.getMonth ()+1)+'-'+LZ(D.getDate( ))

    alert(D)

    all from John Stockton's pages:

    <http://www.merlyn.demo n.co.uk/js-dates.htm>


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

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: date functions

      Paul J. Ettl wrote:
      [color=blue]
      > I use
      >
      > var date1 = new Date();
      >
      > to get todays date. But how can I get yesterdays date?[/color]

      var dYesterday = new Date(new Date().setDate(-1));

      (Works at least in Mozilla/5.0 and IE 6.0 Win.)
      [color=blue]
      > Furthermore I use
      >
      > var ydat = date1.getYear() ;
      > var mdat = date1.getMonth( )+1;
      > var hdat = "0"+date1.getDa te();[/color]
      ^^^^[color=blue]
      > var ddat = hdat.substr(hta g.length-2);
      > var datum=ydat+"-0"+mdat+"-"+ddat;[/color]
      ^^
      You concatenate that always, so you could
      end up with something like 2004-012-031.
      [color=blue]
      > to get a string like 2004-06-01
      >
      > Is there a easier way to format the date?[/color]

      Depends what you mean by that. There is certainly a *better* way:

      // Helper method

      function leadingZero(
      /** @optional string */ s,
      /** @optional number */ n)
      /**
      * @partof
      * http://pointedears.de/scripts/string.js
      * @param s
      * Input string. If omitted and the calling object
      * has a numeric <code>length</code> property, the
      * result of its toString() method is used instead.
      * @param n
      * Length of the resulting string. The default is 1,
      * i.e. if the input string is empty, "0" is returned.
      * @returns the input string with leading zeros so that
      * its length is @{(n)}</code>.
      */
      {
      if (this.length != "undefined"
      && !isNaN(this.len gth)
      && typeof s == "undefined" )
      {
      s = this;
      }

      if (typeof s != "string")
      {
      s = s.toString();
      }

      while (s.length < n)
      {
      s += "0" + s;
      }

      return s;
      }
      String.prototyp e.leadingZero = leadingZero;

      // Featured code

      function date_ymd(d)
      {
      if (!(d instanceof Date))
      {
      if (this instanceof Date)
      {
      d = this;
      }
      else
      {
      d = new Date(d);
      }
      }

      var y = d.getFullYear ? d.getFullYear() : d.getYear();
      if (y < 1900)
      {
      y += 1900;
      }

      return (y
      + "-" + leadingZero(d.g etMonth + 1, 2)
      + "-" + leadingZero(d.g etDate(), 2));
      }
      Date.prototype. ymd = date_ymd;

      var datum = new Date().ymd();
      [color=blue]
      > www.paul.ettl.at[/color]

      This should be part of a signature, delimited with a line containing only
      "-- " (dashDashSpace) . Otherwise repeated posting of this could be
      considered spam.


      PointedEars

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: date functions

        Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> writes:
        [color=blue]
        > Paul J. Ettl wrote:[/color]
        [color=blue]
        > var dYesterday = new Date(new Date().setDate(-1));
        >
        > (Works at least in Mozilla/5.0 and IE 6.0 Win.)[/color]

        Nope. It always becomes the next-to-last day of the previous month,
        which can never be yesterday.

        If you insist on doing it on one line, you can use
        var yesterday = new Date(new Date().setDate( new Date().getDate( )-1));
        Or just do:
        var yesterday = new Date();
        yesterday.setDa te(yesterday.ge tDate()-1);

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Dr John Stockton

          #5
          Re: date functions

          JRS: In article <40C390CC.80609 08@PointedEars. de>, seen in
          news:comp.lang. javascript, Thomas 'PointedEars' Lahn
          <PointedEars@nu rfuerspam.de> posted at Sun, 6 Jun 2004 23:46:52 :[color=blue]
          >Paul J. Ettl wrote:[/color]
          [color=blue]
          > But how can I get yesterdays date?
          >
          >var dYesterday = new Date(new Date().setDate(-1));
          >
          >(Works at least in Mozilla/5.0 and IE 6.0 Win.)[/color]

          I would expect that to give the last day of the previous month, in any
          browser; it does so in MSIE4.

          with (dY = new Date()) setDate(getDate ()-1)

          gives yesterday (at the present time thereof, if possible), and should
          do so in any browser.

          [color=blue]
          >function leadingZero([/color]

          Seems to give wrong result in MSIE4.

          For one who persistently wastes space in complaining about legitimate
          attributions, you so seem to have rather a long-winded programming
          style.

          [color=blue]
          > var y = d.getFullYear ? d.getFullYear() : d.getYear();
          > if (y < 1900)
          > {
          > y += 1900;
          > }[/color]


          I see no point in attempting getFullYear if getYear is being coded for
          satisfactorily.


          [color=blue]
          >This should be part of a signature, delimited with a line containing only
          >"-- " (dashDashSpace) . Otherwise repeated posting of this could be
          >considered spam.[/color]

          Ignore that; the child is deranged. As it stands, it is a legitimate
          part of the body of the message. The proper meaning of the term "spam"
          is Excessive Multiple Posting; thus the term would not apply in any
          case.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          • rh

            #6
            Re: date functions

            Dr John Stockton wrote:

            <snip>
            [color=blue][color=green]
            > >function leadingZero([/color]
            >
            > Seems to give wrong result in MSIE4.
            >[/color]

            I expect it gives the wrong result everywhere because the following
            line in it appears to be badly borken, causing the entire thing to
            fork up:

            s += "0" + s;

            ../rh

            Comment

            • Dr John Stockton

              #7
              Re: date functions

              JRS: In article <ise3nuxi.fsf@h otpop.com>, seen in
              news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
              posted at Mon, 7 Jun 2004 19:23:53 :[color=blue]
              >Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> writes:
              >[color=green]
              >> Paul J. Ettl wrote:[/color]
              >[color=green]
              >> var dYesterday = new Date(new Date().setDate(-1));
              >>
              >> (Works at least in Mozilla/5.0 and IE 6.0 Win.)[/color]
              >
              >Nope. It always becomes the next-to-last day of the previous month,
              >which can never be yesterday.[/color]

              Agreed. I'd forgotten May 31st.

              [color=blue]
              >If you insist on doing it on one line, you can use
              > var yesterday = new Date(new Date().setDate( new Date().getDate( )-1));[/color]

              That may be unsafe, if the month changes between the first and second
              new Date(). Unless one needs to detect the passage of time, new Date()
              should be called only once. Of course, it almost never matters.

              [color=blue]
              >Or just do:
              > var yesterday = new Date();
              > yesterday.setDa te(yesterday.ge tDate()-1);[/color]

              var yesterday = new Date() ; yesterday.setDa te(yesterday.ge tDate()-1) ;
              is on one line ...

              --
              © 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

              • Thomas 'PointedEars' Lahn

                #8
                Re: date functions

                rh wrote:
                [color=blue]
                > Dr John Stockton wrote:
                > <snip>[color=green][color=darkred]
                >> >function leadingZero([/color]
                >>
                >> Seems to give wrong result in MSIE4.[/color]
                >
                > I expect it gives the wrong result everywhere because the following
                > line in it appears to be badly borken, causing the entire thing to
                > fork up:
                >
                > s += "0" + s;[/color]

                Correct. The above line is equivalent to

                s = s + "0" + s;

                It should be

                s = "0" + s;

                of course.


                PointedEars

                Comment

                • rh

                  #9
                  Re: date functions

                  "Paul J. Ettl" <ettl@ettl.at > wrote in message news:<c9hhpt$1s js$1@ulysses.ne ws.tiscali.de>. ..[color=blue]
                  > Two questions:
                  >
                  > I use
                  >
                  > var date1 = new Date();
                  >
                  > to get todays date. But how can I get yesterdays date?
                  >
                  > Furthermore I use
                  >
                  > var ydat = date1.getYear() ;
                  > var mdat = date1.getMonth( )+1;
                  > var hdat = "0"+date1.getDa te();
                  > var ddat = hdat.substr(hta g.length-2);
                  > var datum=ydat+"-0"+mdat+"-"+ddat;
                  >
                  > to get a string like 2004-06-01
                  >
                  > Is there a easier way to format the date?
                  >
                  >[/color]

                  You were on the right track (I assume that the undefined "htag" was
                  something missed in translation).

                  You should be able to left pad with zeros to a width of 2 in basic
                  Javascript by:

                  var paddedStr = ("00"+num).subs tr(-2);

                  Unfortunately, while most recent browsers perform correctly, MS IE
                  fails to meet the current standard for the negative start index for
                  the substr method.

                  A variation on an earlier theme would be to create a general pad
                  function as a prototype. E.g.,

                  // Create the internal pad prototype
                  String.prototyp e._pad = function(width, padChar,side) {
                  var str = [side ? "" : this, side ? this : ""];
                  while (str[side].length < (width ? width : 0)
                  && (str[side] = str[1] +(padChar ? padChar : " ")+str[0] ));
                  return str[side];
                  }

                  // Create pad functions for general use
                  // "width" is the total width to pad to,
                  // "padChar" is the optional pad character -- default " "
                  String.prototyp e.padLeft = function(width, padChar) {
                  return this._pad(width ,padChar,0) };
                  String.prototyp e.padRight = function(width, padChar) {
                  return this._pad(width ,padChar,1) };
                  Number.prototyp e.padLeft = function(width, padChar) {
                  return (""+this).padLe ft(width,padCha r) };
                  Number.prototyp e.padRight = function(width, padChar) {
                  return (""+this).padRi ght(width,padCh ar) };

                  // Date formatting:

                  // Add a getFullYear method if not supported (untested)
                  if (! Date.prototype. getFullYear) {
                  Date.prototype. getFullYear = function() {
                  return this.getYear() + 1900 }
                  }

                  // Create a formatting method for dates as a prototype
                  Date.prototype. dateFmt = function(d) {
                  d = d || this;
                  return d.getFullYear() +"-"+d.getMonth(). padLeft(2,"0")
                  +"-"+d.getDate().p adLeft(2,"0");
                  }

                  // Test

                  alert("Formatte d date: "+ new Date().dateFmt( ) );


                  ../rh

                  Comment

                  • Dr John Stockton

                    #10
                    Re: date functions

                    JRS: In article <290e65a0.04060 72014.7f0c75b1@ posting.google. com>, seen
                    in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Mon, 7
                    Jun 2004 21:14:12 :[color=blue]
                    >"Paul J. Ettl" <ettl@ettl.at > wrote in message news:<c9hhpt$1s js$1@ulysses.ne ws.
                    >tiscali.de>. ..[color=green]
                    >> Two questions:
                    >>
                    >> I use
                    >>
                    >> var date1 = new Date();
                    >>
                    >> to get todays date. But how can I get yesterdays date?
                    >>
                    >> Furthermore I use
                    >>
                    >> var ydat = date1.getYear() ;
                    >> var mdat = date1.getMonth( )+1;
                    >> var hdat = "0"+date1.getDa te();
                    >> var ddat = hdat.substr(hta g.length-2);
                    >> var datum=ydat+"-0"+mdat+"-"+ddat;
                    >>
                    >> to get a string like 2004-06-01
                    >>
                    >> Is there a easier way to format the date?
                    >>
                    >>[/color]
                    >
                    >You were on the right track (I assume that the undefined "htag" was
                    >something missed in translation).
                    >
                    >You should be able to left pad with zeros to a width of 2 in basic
                    >Javascript by:
                    >
                    > var paddedStr = ("00"+num).subs tr(-2);[/color]

                    Left padding to a length of two is so commonly wanted, in comparison
                    with padding to other lengths, that ISTM that it should be done with a
                    specific short-named function. I find a function grammatically more
                    convenient than a method.

                    The input is expected to be an integer in 0..99. Because programmers
                    and users are not infallible, ISTM that for input out of range a
                    function should EITHER give a clear error indication, OR give a string
                    properly representing the numeric value. For the latter case, I use

                    function LZ(x) { return (x<0||x>=10?"": "0") + x }


                    [color=blue]
                    >// Add a getFullYear method if not supported (untested)
                    >if (! Date.prototype. getFullYear) {
                    > Date.prototype. getFullYear = function() {
                    > return this.getYear() + 1900 }
                    >}[/color]

                    I have been informed :-

                    In older Javascript, getYear() returned the year minus 1900, YY only.
                    Later ones, for years after 1999, return the year, YYYY.
                    Before 1900 is worse; expect either of YYYY or YYYY-1900.

                    <p>"GetYear can return any one of these three sequences for years:
                    97,98,99,00,01 or 97,98,99,2000,2 001 or 97,98,99,100,10 1".

                    Just adding 1900 seems unsafe. See below. Indeed, in my MSIE4, new
                    Date().getYear( ) gives 2004 and new Date(1888,8,8). getYear() gives
                    1888.

                    [color=blue]
                    >// Create a formatting method for dates as a prototype
                    >Date.prototype .dateFmt = function(d) {
                    > d = d || this;
                    > return d.getFullYear() +"-"+d.getMonth(). padLeft(2,"0")
                    > +"-"+d.getDate().p adLeft(2,"0");
                    >}[/color]

                    IIRC, there is much to be said for adding 1 to the Month here.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                    Comment

                    • rh

                      #11
                      Re: date functions

                      Dr John Stockton wrote:[color=blue]
                      >
                      > Left padding to a length of two is so commonly wanted, in comparison
                      > with padding to other lengths, that ISTM that it should be done with a
                      > specific short-named function. I find a function grammatically more
                      > convenient than a method.[/color]

                      It may be just a matter of style. I don't really see it as any diffent
                      than any other padding.

                      Nonetheless, what's really wanted, I think, is a number formatting
                      capability that's based on string templates (even early FORTRAN had a
                      FORMAT statement, so the idea's not exactly new :-)). Also, it's not
                      difficult to produce one in Javascript.
                      [color=blue]
                      >
                      > The input is expected to be an integer in 0..99. Because programmers
                      > and users are not infallible, ISTM that for input out of range a
                      > function should EITHER give a clear error indication, OR give a string
                      > properly representing the numeric value. For the latter case, I use
                      >
                      > function LZ(x) { return (x<0||x>=10?"": "0") + x }
                      >
                      >[/color]

                      Agreed, methods that provide a clear indication of success or failure
                      via return value are highly preferrable (and I debated about whether,
                      as a matter of good style, to add them in the sample methods
                      produced).
                      [color=blue]
                      >[color=green]
                      > >// Add a getFullYear method if not supported (untested)
                      > >if (! Date.prototype. getFullYear) {
                      > > Date.prototype. getFullYear = function() {
                      > > return this.getYear() + 1900 }
                      > >}[/color]
                      >
                      > I have been informed :-
                      >
                      > In older Javascript, getYear() returned the year minus 1900, YY only.
                      > Later ones, for years after 1999, return the year, YYYY.
                      > Before 1900 is worse; expect either of YYYY or YYYY-1900.
                      >
                      > <p>"GetYear can return any one of these three sequences for years:
                      > 97,98,99,00,01 or 97,98,99,2000,2 001 or 97,98,99,100,10 1".
                      >
                      > Just adding 1900 seems unsafe. See below. Indeed, in my MSIE4, new
                      > Date().getYear( ) gives 2004 and new Date(1888,8,8). getYear() gives
                      > 1888.
                      >[/color]

                      Which perhaps is sufficient to say attempting to emulate a bad idea is
                      a bad idea? Probably not that hard to improve though, if you can
                      reliably determine the expected range of the year.
                      [color=blue]
                      >[color=green]
                      > >// Create a formatting method for dates as a prototype
                      > >Date.prototype .dateFmt = function(d) {
                      > > d = d || this;
                      > > return d.getFullYear() +"-"+d.getMonth(). padLeft(2,"0")
                      > > +"-"+d.getDate().p adLeft(2,"0");
                      > >}[/color]
                      >
                      > IIRC, there is much to be said for adding 1 to the Month here.[/color]

                      Good recollection :-).

                      Let's make the above

                      return d.getFullYear() +"-"+(d.getMonth() +1).padLeft(2," 0")
                      +"-"+d.getDate().p adLeft(2,"0");

                      in consideration of the fact that getMonth returns a zero-based value.

                      ../rh

                      Comment

                      • Dr John Stockton

                        #12
                        Re: date functions

                        JRS: In article <290e65a0.04060 81446.16db0f28@ posting.google. com>, seen
                        in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Tue, 8
                        Jun 2004 15:46:07 :[color=blue]
                        >
                        >Which perhaps is sufficient to say attempting to emulate a bad idea is
                        >a bad idea? Probably not that hard to improve though, if you can
                        >reliably determine the expected range of the year.[/color]

                        Indeed. But perhaps you have not examined what the newsgroup FAQ has to
                        say on dates.

                        --
                        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                        Comment

                        • rh

                          #13
                          Re: date functions

                          Dr John Stockton <spam@merlyn.de mon.co.uk> wrote in message news:<AmOc1VFXl uxAFww+@merlyn. demon.co.uk>...[color=blue]
                          > JRS: In article <290e65a0.04060 81446.16db0f28@ posting.google. com>, seen
                          > in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Tue, 8
                          > Jun 2004 15:46:07 :[color=green]
                          > >
                          > >Which perhaps is sufficient to say attempting to emulate a bad idea is
                          > >a bad idea? Probably not that hard to improve though, if you can
                          > >reliably determine the expected range of the year.[/color]
                          >
                          > Indeed. But perhaps you have not examined what the newsgroup FAQ has to
                          > say on dates.[/color]

                          From time to time, but I quite often suffer from "retention deficit
                          disorder". Thanks for the reminder.

                          From http://www.merlyn.demon.co.uk/js-date1.htm#TDY:

                          if (!Date.getFullY ear) { // needs full test
                          Date.prototype. getFullYear =
                          new Function("retur n (X=this.getYear ())>999 ? X : 1900+X") }

                          IIRC, there is much to be said for use of "prototype" as part of the
                          test.

                          ../rh

                          Comment

                          • Dr John Stockton

                            #14
                            Re: date functions

                            JRS: In article <290e65a0.04060 91426.601543b7@ posting.google. com>, seen
                            in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Wed, 9
                            Jun 2004 15:26:50 :[color=blue]
                            >Dr John Stockton <spam@merlyn.de mon.co.uk> wrote in message news:<AmOc1VFXl uxAFw
                            >w+@merlyn.demo n.co.uk>...[color=green]
                            >> JRS: In article <290e65a0.04060 81446.16db0f28@ posting.google. com>, seen
                            >> in news:comp.lang. javascript, rh <codeHanger@yah oo.ca> posted at Tue, 8
                            >> Jun 2004 15:46:07 :[color=darkred]
                            >> >
                            >> >Which perhaps is sufficient to say attempting to emulate a bad idea is
                            >> >a bad idea? Probably not that hard to improve though, if you can
                            >> >reliably determine the expected range of the year.[/color]
                            >>
                            >> Indeed. But perhaps you have not examined what the newsgroup FAQ has to
                            >> say on dates.[/color]
                            >
                            >From time to time, but I quite often suffer from "retention deficit
                            >disorder". Thanks for the reminder.
                            >
                            >From http://www.merlyn.demon.co.uk/js-date1.htm#TDY:
                            >
                            > if (!Date.getFullY ear) { // needs full test
                            > Date.prototype. getFullYear =
                            > new Function("retur n (X=this.getYear ())>999 ? X : 1900+X") }
                            >
                            >IIRC, there is much to be said for use of "prototype" as part of the
                            >test.[/color]

                            That's actually in the previous section, #Y2k.

                            I now see that it will not always work, noting the earlier-quoted part
                            of my date2000.htm :

                            "GetYear can return any one of these three sequences for years:
                            97,98,99,00,01 or 97,98,99,2000,2 001 or 97,98,99,100,10 1".

                            Where such a range can be defined, it seems best to take only the last
                            two digits of getYear() and to window them into a 100-year range -
                            possibly a sliding range.

                            That would do for a paediatric or geriatric unit; but not for a general
                            hospital.


                            Otherwise, we know that the answer must be close to YE in
                            YE = Math.round(getT ime() / 864e5 / 365.2425) + 1970
                            but will, rarely, differ by a year; that may affect the first two
                            digits, so it's not possible to use 100*(YE div 100)+Y2 :
                            Y2 = getYear()%100
                            DY = (YE-Y2)%100 ; if (DY>50) DY -= 100 // DY = 0+-1 ?
                            FullYear = YE-DY

                            By using getYear, rather than only getTime, time zone is accommodated.

                            That needs further thought and testing before use. My js-date1,htm is
                            updated.

                            --
                            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                            <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
                            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                            Comment

                            • rh

                              #15
                              Re: date functions

                              Dr John Stockton wrote:

                              <snip>
                              [color=blue][color=green]
                              > >IIRC, there is much to be said for use of "prototype" as part of the
                              > >test.[/color]
                              >[/color]

                              Too subtle, I see :). I believe you intended to use:

                              if (! Date.prototype. getFullYear)

                              in place of:

                              if (!Date.getFullY ear)

                              in the test(s) for pre-existence. Otherwise, a browser supported
                              getFullYear will be overridden, which I would think to be neither the
                              intention nor desirable.

                              <snip>
                              [color=blue]
                              > That needs further thought and testing before use. My js-date1,htm is
                              > updated.[/color]

                              I'll defer to your expertise and further testing on the enhanced
                              version.

                              ../rh

                              Comment

                              Working...