Getdate() over-ride?

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

    Getdate() over-ride?

    I'm trying to produce an array of working days but want to force
    Saturday and Sunday to return the date of the previous Friday, e.g.
    Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
    9/11/04 should return Friday 9/10/04.

    I've tried getdate()-1 and getdate()-2 respectively but am getting
    stack overflow errors. Am I doing anything wrong, or is this just not
    possible?

  • Michael Winter

    #2
    Re: Getdate() over-ride?

    On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bill.edwards@n tlworld.com>
    wrote:
    [color=blue]
    > I'm trying to produce an array of working days but want to force
    > Saturday and Sunday to return the date of the previous Friday, e.g.
    > Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
    > 9/11/04 should return Friday 9/10/04.
    >
    > I've tried getdate()-1 and getdate()-2 respectively but am getting stack
    > overflow errors. Am I doing anything wrong, or is this just not possible?[/color]

    Yes, it's possible, but how can we tell what you've done wrong? You
    haven't shown any code.

    Mike

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

    Comment

    • Evertjan.

      #3
      Re: Getdate() over-ride?

      Bill Edwards wrote on 12 sep 2004 in comp.lang.javas cript:
      [color=blue]
      > I'm trying to produce an array of working days but want to force
      > Saturday and Sunday to return the date of the previous Friday, e.g.
      > Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
      > 9/11/04 should return Friday 9/10/04.
      >
      > I've tried getdate()-1 and getdate()-2 respectively but am getting
      > stack overflow errors. Am I doing anything wrong, or is this just not
      > possible?[/color]

      anything is possible. Please show your code.

      If not ("working days" is defined as mon..fri) please show your definition.


      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress,
      but let us keep the discussions in the newsgroup)

      Comment

      • Lee

        #4
        Re: Getdate() over-ride?

        Bill Edwards said:[color=blue]
        >
        >I'm trying to produce an array of working days but want to force
        >Saturday and Sunday to return the date of the previous Friday, e.g.
        >Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
        >9/11/04 should return Friday 9/10/04.
        >
        >I've tried getdate()-1 and getdate()-2 respectively but am getting
        >stack overflow errors. Am I doing anything wrong, or is this just not
        >possible?[/color]

        Yes, you are doing something wrong, but I don't think any of us
        can guess exactly what it is from that description. Post the URL
        of a web page or s *brief* example that demonstrates the problem.

        There is no "getdate()" method that I know of, so I assume you
        really mean "getDate()" .
        What are you doing with the value after you subtract from it?
        What will your code do on Saturday, January 1, 2005?

        Comment

        • Joseph Numpty

          #5
          Re: Getdate() over-ride?

          >On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bill.edwards@n tlworld.com> wrote:[color=blue]
          >
          >I'm trying to produce an array of working days but want to force
          >Saturday and Sunday to return the date of the previous Friday, e.g.
          >Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
          >9/11/04 should return Friday 9/10/04.
          >
          >I've tried getdate()-1 and getdate()-2 respectively but am getting
          >stack overflow errors. Am I doing anything wrong, or is this just not
          >possible?[/color]

          Do you mean something like this ASP code Bill?

          Function LastBusinessDay (sDate)
          Dim iDay, iDaysToAdd, iDate

          iDaysToAdd = 0
          iDate = sDate

          x = 1

          Do while iDaysToAdd >= 0
          If Weekday(iDate) = 1 or Weekday(iDate) = 7 or _
          isHoliday(iDate ) <> 0 then
          iDay = Weekday(iDate)
          Select Case cint(iDay)
          Case 1 'Sunday
          iDate = DateAdd("d", -1, iDate)
          Case 7 'Saturday
          iDate = DateAdd("d", -1, iDate)
          Case else 'this is a valid day
          if isHoliday(iDate ) > 0 then
          iDate = dateadd("d", -(isHoliday(iDat e)),
          iDate)
          else
          iDaysToAdd = iDaysToAdd - 1
          end if
          End Select
          end if
          Loop

          LastBusinessDay = iDate
          End Function


          Comment

          • Joseph Numpty

            #6
            Re: Getdate() over-ride?

            >On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bill.edwards@n tlworld.com> wrote:[color=blue]
            >
            >I'm trying to produce an array of working days but want to force
            >Saturday and Sunday to return the date of the previous Friday, e.g.
            >Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
            >9/11/04 should return Friday 9/10/04.
            >
            >I've tried getdate()-1 and getdate()-2 respectively but am getting
            >stack overflow errors. Am I doing anything wrong, or is this just not
            >possible?[/color]

            Or something like this VB code?

            Function LastBusDay(ByVa l D As Date) As Date
            Dim D2 As Variant
            D2 = DateSerial(Year (D), Month(D) + 1, 0)
            Do While Weekday(D2) = 1 Or Weekday(D2) = 7
            D2 = D2 - 1
            Loop
            LastBusDay = D2
            End Function

            Comment

            • Dr John Stockton

              #7
              Re: Getdate() over-ride?

              JRS: In article <immak0589cbb5h nkif2nmjjbbp7ea cle7l@4ax.com>, dated
              Mon, 13 Sep 2004 09:31:29, seen in news:comp.lang. javascript, Joseph
              Numpty <joe.numpty@tis cali.co.uk> posted :[color=blue][color=green]
              >>On Sun, 12 Sep 2004 21:29:15 GMT, Bill Edwards <bill.edwards@n tlworld.com>[/color]
              >wrote:[color=green]
              >>
              >>I'm trying to produce an array of working days but want to force
              >>Saturday and Sunday to return the date of the previous Friday, e.g.
              >>Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
              >>9/11/04 should return Friday 9/10/04.
              >>
              >>I've tried getdate()-1 and getdate()-2 respectively but am getting
              >>stack overflow errors. Am I doing anything wrong, or is this just not
              >>possible?[/color]
              >
              >Or something like this VB code?
              >
              >Function LastBusDay(ByVa l D As Date) As Date
              >Dim D2 As Variant
              >D2 = DateSerial(Year (D), Month(D) + 1, 0)
              >Do While Weekday(D2) = 1 Or Weekday(D2) = 7
              >D2 = D2 - 1
              >Loop
              >LastBusDay = D2
              >End Function
              >[/color]

              In a javascript newsgroup, there is much to be said for posting answers
              in javascript. I don't know whether the FAQ actually says that, but I
              believe that it implies it. If you were to read the FAQ, you might well
              find a pointer to information helping with such questions.

              Although it will not matter once, your VB is inefficient; it also
              appears to address a different question.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of 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

              • Dr John Stockton

                #8
                Re: Getdate() over-ride?

                JRS: In article <clf9k017gm5f27 nki5dkedm4r0k7l j0860@4ax.com>, dated
                Sun, 12 Sep 2004 21:29:15, seen in news:comp.lang. javascript, Bill
                Edwards <bill.edwards@n tlworld.com> posted :
                [color=blue]
                >I'm trying to produce an array of working days but want to force
                >Saturday and Sunday to return the date of the previous Friday, e.g.
                >Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
                >9/11/04 should return Friday 9/10/04.[/color]

                You are posting from NTLworld, with a BST time-stamp; therefore, you
                should not be using FFF dates. Follow ISO 8601:2000 / BS EN 28601:1992
                or later. Even Americans should understand that format, since it is
                ANSI X3.30-1985(R1991), FIPS PUB 4-1, 4-2 - the smarter ones actually
                use it. You should use 4-digit years, too.

                [color=blue]
                >I've tried getdate()-1 and getdate()-2 respectively but am getting
                >stack overflow errors. Am I doing anything wrong, or is this just not
                >possible?[/color]

                Yes, you are not showing what you have actually done. Probably you have
                written a recursive routine which (sometimes?) never terminates.
                Perhaps you used = to test equality, perhaps not.

                A Date Object, D, can be reduced to Friday by
                W = D.getDay()
                if (W==0) D.setDate(D.get Date()-2)
                if (W==6) D.setDate(D.get Date()-1)
                or by
                W = D.getDay()
                D.setDate(D.get Date() - (W==0) - (W%6==0) )
                or by
                D.setDate(D.get Date() - [2,0,0,0,0,0,1][D.getDay()])
                or by
                while (D.getDay()%6== 0) D.setDate(D.get Date()-1)

                Read the FAQ carefully; see below. You may then find a better way.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of 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

                • Mick White

                  #9
                  Re: Getdate() over-ride?

                  Dr John Stockton wrote:
                  <snip>[color=blue]
                  >
                  > A Date Object, D, can be reduced to Friday by
                  > W = D.getDay()
                  > if (W==0) D.setDate(D.get Date()-2)
                  > if (W==6) D.setDate(D.get Date()-1)
                  > or by
                  > W = D.getDay()
                  > D.setDate(D.get Date() - (W==0) - (W%6==0) )[/color]

                  W = D.getDay();
                  D.setDate(D.get Date() - (W==0) - (W%6==0) );
                  For some reason this solution induces in me a pleasant feeling.
                  Well done.
                  Mick
                  <snip>

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Getdate() over-ride?

                    Bill Edwards wrote:
                    [color=blue]
                    > I'm trying to produce an array of working days but want to force
                    > Saturday and Sunday to return the date of the previous Friday, e.g.
                    > Sunday 9/12/04 should return Friday 9/10/04 and similarly Saturday
                    > 9/11/04 should return Friday 9/10/04.
                    >
                    > I've tried getdate()-1 and getdate()-2 respectively but am getting
                    > stack overflow errors. Am I doing anything wrong, or is this just not
                    > possible?[/color]

                    From what I can tell without any source code, most certainly you
                    do something wrong. There is no built-in getdate() method (it's
                    `getDate()'), so it is likely that you are recursively calling
                    your own method. Stack overflow errors often indicate infinite
                    recursion.


                    PointedEars
                    --
                    Now better! It crashes 32% faster than Win95

                    Comment

                    • Evertjan.

                      #11
                      Re: Getdate() over-ride?

                      Thomas 'PointedEars' Lahn wrote on 19 sep 2004 in comp.lang.javas cript:[color=blue]
                      > Stack overflow errors often indicate infinite
                      > recursion.[/color]

                      I would suggest, Thomas,
                      that infinite recursion means no stack overflow error.

                      ;-)

                      --
                      Evertjan.
                      The Netherlands.
                      (Please change the x'es to dots in my emailaddress,
                      but let us keep the discussions in the newsgroup)

                      Comment

                      Working...