date compare within 90days?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • soni2926@yahoo.com

    date compare within 90days?

    Hi,
    I have a function where i need to check the date passed in is within
    90days of today. Could someone help me get this to work, how do i do
    the 90 days compare with today?
    <script language='javas cript'>
    function CheckDate(produ ctDate)
    {
    var dateVar = new Date(productDat e);
    //alert(dateVar);
    var today = new Date();
    //alert(today);
    alert( today.getDate()-dateVar.getDate () );
    }
    </script>

    I'm subtracting the date, tried timed, but can't figure out what's it
    returning.
  • Tom de Neef

    #2
    Re: date compare within 90days?

    soni2926@yahoo. com:
    I have a function where i need to check the date passed in is within
    90days of today. Could someone help me get this to work, how do i do
    the 90 days compare with today?
    <script language='javas cript'>
    function CheckDate(produ ctDate)
    {
    var dateVar = new Date(productDat e);
    //alert(dateVar);
    var today = new Date();
    //alert(today);
    alert( today.getDate()-dateVar.getDate () );
    }
    </script>
    >
    I'm subtracting the date, tried timed, but can't figure out what's it
    returning.
    miliseconds ?
    divide by 86 400 000 (nr of miliseconds in a day).
    Tom


    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: date compare within 90days?

      soni2926@yahoo. com wrote:
      I have a function where i need to check the date passed in is within
      90days of today.
      Parse error. Are you talking about 90 days or about 3 months? Before or
      since today?
      Could someone help me get this to work, how do i do
      the 90 days compare with today?
      <script language='javas cript'>
      <script type="text/javascript">
      function CheckDate(produ ctDate)
      {
      var dateVar = new Date(productDat e);
      //alert(dateVar);
      var today = new Date();
      //alert(today);
      alert( today.getDate()-dateVar.getDate () );
      }
      </script>
      >
      I'm subtracting the date,
      Wrong aproach.
      tried timed,
      Pardon?
      but can't figure out what's it returning.
      It *is evaluated to* the number of milliseconds between the dates, with
      the provision of its being off by -3'600'000 milliseconds (standard to DST)
      or +3'600'000 milliseconds (DST to standard) if DST switching occurs in
      between. Therefore, subtraction is the wrong approach here.

      var now = new Date(), later = new Date(), before = new Date();

      // 90 days from now
      later.setDate(n ow.getDate() + 90);

      // 90 days ago
      before.setDate( now.getDate() - 90);

      You can compare the set date with any given date then.

      If you mean months, use getMonth() and setMonth(), respectively.


      HTH

      PointedEars
      --
      Anyone who slaps a 'this page is best viewed with Browser X' label on
      a Web page appears to be yearning for the bad old days, before the Web,
      when you had very little chance of reading a document written on another
      computer, another word processor, or another network. -- Tim Berners-Lee

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: date compare within 90days?

        Tom de Neef wrote:
        soni2926@yahoo. com:
        >[...]
        > alert( today.getDate()-dateVar.getDate () );
        > }
        ></script>
        >>
        >I'm subtracting the date, tried timed, but can't figure out what's it
        >returning.
        >
        miliseconds ?
        More or less.
        divide by 86 400 000 (nr of miliseconds in a day).
        Won't work precisely until they have abolished DST and implementations have
        taken that into account.


        PointedEars
        --
        var bugRiddenCrashP ronePieceOfJunk = (
        navigator.userA gent.indexOf('M SIE 5') != -1
        && navigator.userA gent.indexOf('M ac') != -1
        ) // Plone, register_functi on.js:16

        Comment

        • roamy@web.de

          #5
          Re: date compare within 90days?

          for shure you meant a function in this way ?


          <script language='javas cript'>
          function CheckDate(produ ctDate)
          {
          var dateVar = Date.parse( productDate );
          //alert(dateVar);
          var today = new Date();
          var Nr_of_Days = ( Date.parse( today ) - dateVar ) / 86400000;
          alert( Nr_of_Days );
          }
          </script>

          Comment

          • Jeremy J Starcher

            #6
            Re: date compare within 90days?

            On Mon, 14 Apr 2008 10:07:40 -0700, roamy wrote:
            var Nr_of_Days = ( Date.parse( today ) - dateVar ) / 86400000;
            This fails to take daylight savings time changes into account.

            getDate() +/- 90 is a much better and bullet proof approach.

            Comment

            • Dr J R Stockton

              #7
              Re: date compare within 90days?

              In comp.lang.javas cript message <48038B8C.70306 @PointedEars.de >, Mon, 14
              Apr 2008 18:51:24, Thomas 'PointedEars' Lahn <PointedEars@we b.de>
              posted:
              >
              var now = new Date(), later = new Date(), before = new Date();
              >
              // 90 days from now
              later.setDate(n ow.getDate() + 90);
              >
              var now = new Date(), later = new Date(+now), before = new Date(+now);

              should be somewhat more efficient and also proof against improbable
              nocturnal inconsistency. Using new Date() requires that the OS supplies
              the date and time, which is not necessarily held in the form that a date
              Object holds; but using new Date(+now) merely requires creation of the
              Object and copying a Double. The + is not always necessary; omitting it
              in this case should do no actual harm, but wastes machine time in IE.

              If started VERY late in the day, before could get tomorrow.

              The OP should check the exact intent of "within 90 days"; is the 90th
              day allowed?

              --
              (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05.
              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

              • D. Stussy

                #8
                Re: date compare within 90days?

                "Thomas 'PointedEars' Lahn" <PointedEars@we b.dewrote in message
                news:48038C17.3 070400@PointedE ars.de...
                Tom de Neef wrote:
                soni2926@yahoo. com:
                [...]
                alert( today.getDate()-dateVar.getDate () );
                }
                </script>
                >
                I'm subtracting the date, tried timed, but can't figure out what's it
                returning.
                miliseconds ?
                >
                More or less.
                >
                divide by 86 400 000 (nr of miliseconds in a day).
                >
                Won't work precisely until they have abolished DST and implementations
                have
                taken that into account.
                Why? Both times should be in UTC which disregards DST/Summertime (as it's
                called in Europe).


                Comment

                • Lee

                  #9
                  Re: date compare within 90days?

                  soni2926@yahoo. com said:
                  >
                  >Hi,
                  >I have a function where i need to check the date passed in is within
                  >90days of today. Could someone help me get this to work, how do i do
                  >the 90 days compare with today?
                  ><script language='javas cript'>
                  function CheckDate(produ ctDate)
                  {
                  var dateVar = new Date(productDat e);
                  //alert(dateVar);
                  var today = new Date();
                  //alert(today);
                  alert( today.getDate()-dateVar.getDate () );
                  }
                  ></script>
                  >
                  >I'm subtracting the date, tried timed, but can't figure out what's it
                  >returning.
                  And none of the available on-line documentation was any help?


                  --

                  Comment

                  • Dr J R Stockton

                    #10
                    Re: date compare within 90days?

                    In comp.lang.javas cript message <ZrMMj.5797$GE1 .993@nlpi061.nb dc.sbc.com
                    >, Mon, 14 Apr 2008 17:25:13, Jeremy J Starcher <r3jjs@yahoo.co m>
                    posted:
                    >On Mon, 14 Apr 2008 10:07:40 -0700, roamy wrote:
                    >
                    > var Nr_of_Days = ( Date.parse( today ) - dateVar ) / 86400000;
                    >
                    >This fails to take daylight savings time changes into account.
                    Perhaps more importantly, it fails to take the time of today into
                    account. Nr_of_Days describes an integer.

                    Since today is a Date Object, +today should be better than
                    Date.parse(toda y) which will go via a String - slow, and loses the
                    milliseconds - and, as there is a subtraction, the + is not needed.

                    --
                    (c) John Stockton, nr London UK. ???@merlyn.demo n.co.uk Turnpike v6.05 MIME.
                    Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
                    Check boilerplate spelling -- error is a public sign of incompetence.
                    Never fully trust an article from a poster who gives no full real name.

                    Comment

                    • Thomas 'PointedEars' Lahn

                      #11
                      Re: date compare within 90days?

                      D. Stussy wrote:
                      "Thomas 'PointedEars' Lahn" [...] wrote [...]
                      >Tom de Neef wrote:
                      >>soni2926@yahoo. com:
                      >>>[...]
                      >>> alert( today.getDate()-dateVar.getDate () );
                      >>> }
                      >>></script>
                      >>>>
                      >>>I'm subtracting the date, tried timed, but can't figure out what's it
                      >>>returning.
                      >>miliseconds ?
                      >More or less.
                      >>
                      >>divide by 86 400 000 (nr of miliseconds in a day).
                      >Won't work precisely until they have abolished DST and implementations
                      have
                      ^^^^^^
                      >taken that into account.
                      >
                      Why? Both times should be in UTC which disregards DST/Summertime (as it's
                      called in Europe).
                      But they are not.

                      Please use ân app that deserves to be called a newsreader for accessing Usenet.


                      PointedEars
                      --
                      var bugRiddenCrashP ronePieceOfJunk = (
                      navigator.userA gent.indexOf('M SIE 5') != -1
                      && navigator.userA gent.indexOf('M ac') != -1
                      ) // Plone, register_functi on.js:16

                      Comment

                      • Dr J R Stockton

                        #12
                        Re: date compare within 90days?

                        In comp.lang.javas cript message <fu1kpi$55b$1@s narked.org>, Mon, 14 Apr
                        2008 23:48:18, D. Stussy <spam@bde-arc.ampr.orgpos ted:
                        >"Thomas 'PointedEars' Lahn" <PointedEars@we b.dewrote in message
                        >news:48038C17. 3070400@Pointed Ears.de...
                        >Tom de Neef wrote:
                        soni2926@yahoo. com:
                        >[...]
                        > alert( today.getDate()-dateVar.getDate () );
                        > }
                        ></script>
                        >>
                        >I'm subtracting the date, tried timed, but can't figure out what's it
                        >returning.
                        >
                        miliseconds ?
                        >>
                        >More or less.
                        >>
                        divide by 86 400 000 (nr of miliseconds in a day).
                        >>
                        >Won't work precisely until they have abolished DST and implementations
                        >have
                        >taken that into account.
                        >
                        >Why? Both times should be in UTC which disregards DST/Summertime (as it's
                        >called in Europe).
                        When a difference of 90 days is called for, that in normal circumstances
                        means calendar days; and those vary in length. Merely dividing the
                        number of seconds by 86400 is naive.

                        --
                        (c) John Stockton, nr London, UK. ?@merlyn.demon. co.uk Turnpike v6.05.
                        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

                        Working...