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

Date math

Expand Messages
  • Julie
    Is there a clip function that can do date math , for lack of a better word for it? Say I wanted to generate a list of Fridays and their dates for the next
    Message 1 of 3 , Jul 4, 2003
    • 0 Attachment
      Is there a clip function that can do "date math", for lack of a better word
      for it? Say I wanted to generate a list of Fridays and their dates for the
      next year for a schedule. Can that be accomplished in a clip? I know I can
      do this in a Calendar type program, just wondering if it could be done in NTP.

      thanks,
      Julie
    • Martyn Folkes
      I have a clip that may be of some help, or at least give you some ideas. It has been well tested and all bugs found so far have been removed. Beware the long
      Message 2 of 3 , Jul 4, 2003
      • 0 Attachment
        I have a clip that may be of some help, or at least give you some ideas. It
        has been well tested and all bugs found so far have been removed. Beware the
        long lines. Let me know if you can't get it to work and I will try to help.

        Martyn

        ---clip begins---

        ;***CalcDate by Martyn Folkes***
        ;This clip requires %interval% to hold a positive integer representing the
        number of days by which to increment or decrement the date. The result will
        be returned in %d% (d), %dd% (dd), %m% (m), %mm% (mm), %yy% (yy) and %yyyy%
        (yyyy), the month name in %mmmm%, the day name in %day%, the day of the year
        (1-365 or 366) in %doy%, the day number (1=Sunday, 2=Monday...) in %dn%, the
        day name in %day% and the day suffix (st,nd,rd,th) in %ds%. Also, %leap%
        contains 29 if it is a leap year or 28 if it is not a leap year.
        ;If %startdate% contains a date (ddmmyyyy) the calculation will be from that
        date, otherwise, if %startdate% contains 1 or is empty, the calculation will
        be from today's date.

        ^!IfTrue ^%startdate% TODAY
        ^!IfTrue ^$IsEmpty(^%startdate%)$ TODAY
        ^!Set %d%=^$StrCopyLeft("^%startdate%";2)$;
        %m%=^$StrCopy("^%startdate%";3;2)$; %yyyy%=^$StrCopyRight("^%startdate%";4)$
        ^!Goto CALCDATE

        :TODAY
        ^!Set %d%=^$GetDate(d)$; %m%=^$GetDate(m)$; %yyyy%=^$GetDate(yyyy)$

        :CALCDATE
        ^!SetArray %array%=0;31;28;31;30;31;30;31;31;30;31;30;31
        ^!Inc %d% ^%interval%
        ^!If ^%d% < 1 NEG
        ^!If ^%m% = 2 FEB
        ^!If ^%m% = 4 30DAY
        ^!If ^%m% = 6 30DAY
        ^!If ^%m% = 9 30DAY
        ^!If ^%m% = 11 30DAY
        ^!Goto 31DAY

        :NEG
        ^!Prompt Unable to calculate for this negative number. Try again soon...
        ^!Goto END

        :FEB
        ;Every year divisible by 4 is a leap year, but years divisible by 100 are
        not leap years, except years divisible by 400 which ARE leap years.
        ^!Set %leap%=28
        ^!If ^$Calc(^%yyyy%mod4)$=0 ^!Set %leap%=29
        ^!If ^$Calc(^%yyyy%mod100)$=0 ^!Set %leap%=28
        ^!If ^$Calc(^%yyyy%mod400)$=0 ^!Set %leap%=29
        ^!If ^%d% <= ^%leap% ^!Goto YEARCHECK
        ^!Inc %m%
        ^!Dec %d% ^%leap%
        ^!Goto FEB

        :30DAY
        ^!If ^%d% <= 30 ^!Goto YEARCHECK
        ^!Inc %m%
        ^!Dec %d% 30
        ^!Goto 30DAY

        :31DAY
        ^!If ^%d% <= 31 ^!Goto YEARCHECK
        ^!Inc %m%
        ^!Dec %d% 31
        ^!Goto 31DAY

        :YEARCHECK
        ^!If ^%m% >12 NEXT ELSE FINISH
        ^!Dec %m% 12
        ^!Inc %yyyy%
        ^!Goto YEARCHECK

        :FINISH
        ;day of the year
        ^!If ^%leap%=29 NEXT ELSE SKIP_2
        ^!SetArray %array%=0;31;60;91;121;152;182;213;244;274;305;335
        ^!Goto SKIP
        ^!SetArray %array%=0;31;59;90;120;151;181;212;243;273;304;334
        ^!Set %doy%=^$Calc(^%array^%m%%+^%d%)$

        ;month name
        ^!SetArray
        %array%=January;February;March;April;May;June;July;August;September;October;
        November;December
        ^!Set %mmmm%=^%array^%m%%

        ;day name (I found the algorithm for this at
        http://www.tondering.dk/claus/cal/node1.html).
        ^!SetArray %array%=Sunday;Monday;Tuesday;Wednesday;Thursday;Friday;Saturday
        ^!Set %dna%=^$Calc(INT((14-^%m%)/12))$
        ^!Set %dny%=^$Calc(^%yyyy%-^%dna%)$
        ^!Set %dnm%=^$Calc(^%m%+(12*^%dna%)-2)$
        ^!Set
        %dn%=^$Calc((((^%d%)+(^%dny%)+INT(^%dny%/4)-INT(^%dny%/100)+INT(^%dny%/400)+
        INT((31*^%dnm%)/12)) MOD 7)+1)$
        ^!Set %day%=^%array^%dn%%

        ;day suffix
        ^!SetArray
        %array%=st;nd;rd;th;th;th;th;th;th;th;th;th;th;th;th;th;th;th;th;th;st;nd;rd
        ;th;th;th;th;th;th;th;st
        ^!Set %ds%=^%array^%d%%

        ;2-digit day, month, year
        ^!Set %dd%=^$StrCopyRight("0^%d%";2)$; %mm%=^$StrCopyRight("0^%m%";2)$;
        %yy%=^$StrCopyRight("^%yyyy%";2)$

        ^!Goto END

        ---clip ends---

        > -----Original Message-----
        > From: Julie [mailto:gleits@...]
        > Sent: 04 July 2003 13:51
        > To: ntb-clips@yahoogroups.com
        > Subject: [Clip] Date math
        >
        >
        > Is there a clip function that can do "date math", for lack of a
        > better word
        > for it? Say I wanted to generate a list of Fridays and their
        > dates for the
        > next year for a schedule. Can that be accomplished in a clip? I
        > know I can
        > do this in a Calendar type program, just wondering if it could be
        > done in NTP.
        >
        > thanks,
        > Julie
        >
        >
        >
        >
        >
        >
        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
        >
        >
      • John Zeman
        Hey Julie, In addition to what Larry and Marten suggested you might take a peek at ntp-clips msg# 6522 posted by Steve Veltkamp who had responded to somewhat
        Message 3 of 3 , Jul 4, 2003
        • 0 Attachment
          Hey Julie,

          In addition to what Larry and Marten suggested you might take a peek
          at ntp-clips msg# 6522 posted by Steve Veltkamp who had responded to
          somewhat similar question from me a couple years ago.

          In that msg he submitted one of the most commonly used clips
          (slightly modified for my own needs) I have in my libraries. You
          input any date in short format i.e. 7/2/2003 and it outputs that date
          in a long format such as Wednesday, July 04, 2003.

          To use his clips split what he posted into two separate clips that
          reside in the same library. The top section being the clip you
          actually run, and the DOW section below being a separate stand alone
          clip.

          John

          --- In ntb-clips@yahoogroups.com, Julie <gleits@c...> wrote:
          > Is there a clip function that can do "date math", for lack of a
          better word
          > for it? Say I wanted to generate a list of Fridays and their dates
          for the
          > next year for a schedule. Can that be accomplished in a clip? I
          know I can
          > do this in a Calendar type program, just wondering if it could be
          done in NTP.
          >
          > thanks,
          > Julie
        Your message has been successfully submitted and would be delivered to recipients shortly.