Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] Date Question

Expand Messages
  • Wayne VanWeerthuizen
    ... Then further down the ^!If ^%Month%=12 gets triggered, which you do not want to happen if you ve already changed it. In order to avoid changing the month
    Message 1 of 2 , Nov 2, 2000
    • 0 Attachment
      Elizabeth Wild <ewild@...> wrote:

      > I am trying to come up with a Clip routine which will handle the end of the
      > month. I want to use this to pull a file which has the previous date in
      > its name. Most days it is easy to do this, However, once a month it
      > becomes more difficult. This is the clip I have written so far. I used the
      > label becasue I anticipate this being part of a larger routine. I printed
      > the two variables at the end so that I could determine whether or not it
      > was working. As written currently, the clip produces %Month%=11 and
      > %Day%=31. If I comment out all of the months but November, then it returns
      > %Month%=10 and %Day%=31.
      >
      > Does anyone have suggestions for how to make this work?
      >
      > Clip:
      >
      > ^!Set %Month%=^$GetDate(mm)$
      > ^!Set %Day%=^$Calc(^$GetDate(dd)$-1)$
      > ^!If ^%Day%=0 Marvin
      >
      > :Marvin
      > ^!If ^%Month%=01 Next Else Skip 1
      > ^!Set %Month%=12; %Day%=31

      Then further down the ^!If ^%Month%=12 gets triggered,
      which you do not want to happen if you've already
      changed it. In order to avoid changing the month
      twice, the above needs to be:

      ^!If ^%Month%=01 Next Else Skip 2
      ^!Set %Month%=12; %Day%=31
      ^!Goto DoneTestingMonths

      > ^!If ^%Month%=02 Next Else Skip 1
      > ^!Set %Month%=01; %Day%=31
      > ^!If ^%Month%=03 Next Else Skip 1
      > ^!Set %Month%=02; %Day%=28
      > ^!If ^%Month%=04 Next Else Skip 1
      > ^!Set %Month%=03; %Day%=31
      > ^!If ^%Month%=05 Next Else Skip 1
      > ^!Set %Month%=04; %Day%=30
      > ^!If ^%Month%=06 Next Else Skip 1
      > ^!Set %Month%=05; %Day%=31
      > ^!If ^%Month%=07 Next Else Skip 1
      > ^!Set %Month%=06; %Day%=30
      > ^!If ^%Month%=08 Next Else Skip 1
      > ^!Set %Month%=07; %Day%=31
      > ^!If ^%Month%=09 Next Else Skip 1
      > ^!Set %Month%=08; %Day%=31
      > ^!If ^%Month%=10 Next Else Skip 2
      > ^!Set %Month%=09; %Day%=30
      > ^!If ^%Month%=11 Next Else Skip 1
      > ^!Set %Month%=10; %Day%=31
      > ^!If ^%Month%=12 Next Else Skip 1
      > ^!Set %Month%=11; %Day%=31

      Add a label here:

      :DoneTestingMonths





      Alternatively, you could use this clip instead:

      ^!Set %Month%=^$GetDate(mm)$
      ^!Set %Day%=^$Calc(^$GetDate(dd)$-1)$
      ^!If ^%Day% = 0 SameMonth
      ^!If ^%Month%=01 ^!Set %Month%=99; %Day%=99
      ^!If ^%Month%=02 ^!Set %Month%=01; %Day%=31
      ^!If ^%Month%=03 ^!Set %Month%=02; %Day%=28
      ^!If ^%Month%=04 ^!Set %Month%=03; %Day%=31
      ^!If ^%Month%=05 ^!Set %Month%=04; %Day%=30
      ^!If ^%Month%=06 ^!Set %Month%=05; %Day%=31
      ^!If ^%Month%=07 ^!Set %Month%=06; %Day%=30
      ^!If ^%Month%=08 ^!Set %Month%=07; %Day%=31
      ^!If ^%Month%=09 ^!Set %Month%=08; %Day%=31
      ^!If ^%Month%=10 ^!Set %Month%=09; %Day%=30
      ^!If ^%Month%=11 ^!Set %Month%=10; %Day%=31
      ^!If ^%Month%=12 ^!Set %Month%=11; %Day%=30
      ^!If ^%Month%=99 ^!Set %Month%=12; %Day%=31
      :SameMonth





      Here is another clip which uses a different approach. It handles
      leap years, and ensures that dates and months are shown with
      two digits. A few different neat techniques are demonstrated
      in this clip, so its a good clip to study.


      H="Get Yesterdays Date - Demonstration Clip"

      ; ;Automatically Set Todays Date
      ; ^!Set %Month%="^$GetDate(mm)$"
      ; ^!Set %Day%="^$GetDate(dd)$"
      ; ^!Set %Year%=^$GetDate(yyyy)$

      ; Prepare Wizard to Ask for Desired Date
      ^!ClearVariable %Wizard%
      ^!Append %Wizard%="%Month%="^?{Month=^$GetDate(mm)$}"; "
      ^!Append %Wizard%="%Day%="^?{Day=^$GetDate(dd)$}"; "
      ^!Append %Wizard%="%Year%="^?{Year=^$GetDate(yyyy)$}""
      ^!SetWizardLabel Enter Date To Test
      ; Show Wizard
      ^!Set ^%Wizard%

      ; Remember choosen date, to display at end.
      ^!Inc %Day% 0
      ^!If ^%Day% < 10 ^!Set %Day%="0^%Day%"
      ^!Inc %Month% 0
      ^!If ^%Month% < 10 ^!Set %Month%="0^%Month%"
      ^!Set %Today%="Today: ^%Year%-^%Month%-^%Day%"

      :CalculateYesturdaysDate
      ^!Dec %Day%
      ^!If ^%Day% < 10 ^!Set %Day%="0^%Day%"
      ^!If ^%Day% > 0 FinishedDateCalculation

      :LastDayOfPreviousMonth
      ^!Dec %Month%
      ^!If ^%Month% < 1 ^!Dec %Year%
      ^!If ^%Month% < 1 ^!Set %Month%="12"
      ^!If ^%Month% < 10 ^!Set %Month%="0^%Month%"
      ^!Set %MonthData%="31 28 31 30 31 30 31 31 30 31 30 31 "
      ^!Set %Day%=^$StrCopy("^%MonthData%";^$Calc(^%Month%*3-2;0)$;2)$
      ^!If ^%Month% = 2 Next Else FinishedDateCalculation

      :LeapYearRules
      ^!If ^$Calc(^%Year% MOD 4;0)$ = 0 ^!Inc %Day%
      ^!If ^$Calc(^%Year% MOD 100;0)$ = 0 ^!Dec %Day%
      ^!If ^$Calc(^%Year% MOD 400;0)$ = 0 ^!Inc %Day%

      :FinishedDateCalculation
      ^!Info [R] ^%Today% ^P Yesturday: ^%Year%-^%Month%-^%Day% ^P







      These clips I tested somewhat, but I was up too late and
      needed to get to sleep, so the testing was not as complete as
      it could be and errors may remain. ;-)







      --
      Wayne M. VanWeerthuizen
      Homepage: http://landru.myhome.net/wayne
    Your message has been successfully submitted and would be delivered to recipients shortly.