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

Re: [Clip] Easier Date Question

Expand Messages
  • Alan
    Hi, I gather that it is not the current date and/or time that you are or that you need to work with but instead, you obtain a date from a doc and then that
    Message 1 of 9 , Sep 3, 2004
    • 0 Attachment
      Hi,

      I gather that it is not the current date and/or time that you are or
      that you need to work with but instead, you obtain a date from a doc and
      then that what you are asking how to do is to reformat and output that
      date ?

      I mentioned that because Ntab has a function that returns the current
      date and/or time. it is: $^getdate(your-filter-goes-here)$

      help > help on clip programming > click the index tab > scroll down to:
      $^getdate

      so as to reference on that.
      --
      But if I'm correct on what you want, then what you want **has nothing to
      do with the above mentioned getdate function.** Instead, you need to
      recognize date digits and/[or months (alpha, not numeric)] then convert
      and output into your desired formats.

      > Given a string which can be set as a variable (%DocDate%) can we get
      > Notetab to recognize that it is a date?

      likely could nearly or perhaps nearly enough approximate such
      recognition using a regular expression to do so. Something that would
      work using regexp
      >
      > For instance, in my doc, the date appears in any one of the
      > following formats:
      > March 01, 2004
      > MAR 1 2004
      > 03/01/2004
      > 03/01/04
      >
      > I can select the string, set the variable, but then I need to output
      > the date in 2 places in 2 different formats:
      > YYYY-MM-DD AND MM/DD/YYYY.

      Alright. Likely not too difficult using a regexp when it's all digits.
      But when it's alpha as well as numeric then it appears to me that you
      would need to create and use a "look up table" so to speak. For
      example, looks up (looks in either another clip, a data clip, or a data
      file) "MAR" and returns its numeric equivalent of 03

      you might have to scan with two regex, one for the numeric, the other to
      find the alpha. But a regex guru might able, yes I just realized it can
      incorporate all into one regex using the |

      (in regex geek) for example: MAR|03

      finds for MAR and/or also finds for 03

      help > help topics > click index tab > scroll down to RegExp
      --

      I think Ntab can do what you want. Did I hear Perl? Yes, Perl could do
      it as well.

      --
      Alan.
    • Hugo Paulissen
      ... Jody, Rayellen, This might not be the smartest of clips but it does manipulate the dates in the given formats to the desired output. The regex is not
      Message 2 of 9 , Sep 3, 2004
      • 0 Attachment
        > I've been up all night, so unless somebody else grabs this which
        > is fine by me ;), I'll play around with it later today/tonight/
        > tomorrow. Good NoteNite. ;)

        Jody, Rayellen,

        This might not be the smartest of clips but it does manipulate the
        dates in the given formats to the desired output.

        The regex is not tested (I had "\W+\w\d+,*\w\d+" first, which looks
        nicer, but is greedier), but apparently that isn't Ray's problem. I
        left it in - I thought the question was more about the latter part of
        the clip... Look out for the long line starting with ^!Set %YYYY%

        ^!Find "\W+[\s\/]\d+,*[\s\/]\d+" SIR
        ^!IfError EXIT
        ^!Set %Date%=^$GetSelection$
        ;GET RID OF SUPERFLUOUS CHARS
        ^!Set %Date%=^$StrReplace("/";" ";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace(",";"";"^%Date%";0;0)$
        ;BULK REPLACEMENT IF IT'S AFTER 12
        ^!Set %Date%=^$StrReplace("january";"01";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("jan";"01";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("february";"02";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("feb";"02";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("march";"03";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("mar";"03";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("april";"04";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("apr";"04";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("may";"05";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("june";"06";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("jun";"06";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("july";"07";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("jul";"07";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("august";"08";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("aug";"08";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("september";"09";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("sep";"09";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("october";"10";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("oct";"10";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("november";"11";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("nov";"11";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("december";"12";"^%Date%";0;0)$
        ^!Set %Date%=^$StrReplace("dec";"12";"^%Date%";0;0)$
        ;GETTING THINGS RIGHT
        ^!Set %MM%=^$strCopyLeft(^%Date%;2)$
        ^!Set %DDtemp%=^$StrDeleteLeft("^%Date%";2)$
        ^!Set %DDtemp%=^$strTrim(^%DDtemp%)$
        ^!Set %DD%=^$strCopyLeft(^%DDtemp%;^$StrPos(" ";"^%DDtemp%";0)$)$
        ^!If ^$StrSize("^$strTrim(^%DD%)$")$=1 ^!SET %DD%=0^%DD%
        ^!Set %DD%=^$strTrim(^%DD%)$
        ^!Set %YYYY%=^$StrDeleteLeft("^%DDtemp%";^$StrPos(" ";"^%DDtemp%";0)$)
        $
        ^!If ^$StrSize("^$strTrim(^%YYYY%)$")$=2 ^!SET %YYYY%=20^%YYYY%
        ^!INFO ^%YYYY%-^%MM%-^%DD% or ^%MM%/^%DD%/^%YYYY%

        Hugo
      • Alan C.
        ... [ . . ] ... The enclosed clip: 1. puts 12 months into array (alphalist) 2. replace each space with a / 2b. replace , with nothing 2c. puts the date string
        Message 3 of 9 , Sep 5, 2004
        • 0 Attachment
          On Fri, 03 Sep 2004 15:48:59 -0700, Alan wrote:
          >�Hi,
          [ . . ]
          >>�For instance, in my doc, the date appears in any one of the
          >>�following formats:
          >>�March 01, 2004
          >>�MAR 1 2004
          >>�03/01/2004
          >>�03/01/04
          >>
          >>�I can select the string, set the variable, but then I need to output
          >>�the date in 2 places in 2 different formats:
          >>�YYYY-MM-DD AND MM/DD/YYYY.

          The enclosed clip:
          1. puts 12 months into array (alphalist)
          2. replace each space with a /
          2b. replace , with nothing
          2c. puts the date string into a 3 item array (mdy)
          3. works/processes separately on each ie mdy1, mdy2, mdy3
          4. manipulates any and all digits during very first stage/section of clip
          5. soon then checks for an alpha string, checks for it on mdy1
          6. if not alpha string, then finaloutput real quick like
          7. or, if is yes alpha string then goto proc (process) alphaitem (procalphaitem). this proc re loops, iterates, comparing each month in alphalist to mdy1 (really at that point mdy1 is or has become: mdy1 > alphaitem > MM). if yes, a match, then substitutes the correct digit replaces the alpha. or, if not a match (foreign calendar item, etc.) then emergency exits the loop, goes to error message at bottom of clip.
          --
          March 01, 2004
          MAR 1 2004
          03/01/2004
          03/01/04
          October 03, 2004
          gaf 04, 2004

          from those, select a line, try the clip if you like.
          the next clip also works if select that gaf month line there :-)
          (Well, ya never know - a Martian calendar might have or use something like that) :-)
          longest clip line equals 59 characters. Clip enclosed next.

          H="date-manip"
          ^!clearvariables
          ^!Set %Date%=^$GetSelection$
          ^!Set %Date%=^$StrReplace(" ";"/";"^%Date%";0;0)$
          ^!Set %Date%=^$StrReplace(",";"";"^%Date%";0;0)$

          ^!Append %alphalist%=jan;feb;mar;apr;may;jun;jul;aug
          ^!SetArray %alphalist%=^%alphalist%;sep;oct;nov;dec

          ^!SetListDelimiter /
          ^!SetArray %mdy%=^%Date%
          ; ^!Info ^%mdy1%~^%mdy2%~^%mdy3%

          ^!Set %DD%=^%mdy2%
          ^!Set %length%=^$StrSize("^%DD%")$
          ^!If ^%length% => 2 skip
          ^!Set %DD%=0^%DD%

          ^!Set %YYYY%=^%mdy3%
          ^!Set %length%=^$StrSize("^%YYYY%")$
          ^!If ^%length% => 4 skip
          ^!Set %YYYY%=20^%YYYY%

          ^!IfTrue ^$IsAlpha("^%mdy1%")$ procalphaitem
          ^!Set %MM%=^%mdy1%

          :finaloutput
          ^!Info ^%YYYY%-^%MM%-^%DD%^p^%MM%/^%DD%/^%YYYY%
          ^!clearvariables
          ^!Goto end

          :procalphaitem
          ^!Set %alphaitem%=^$StrCopyLeft("^%mdy1%";3)$
          ^!Set %alphaitem%=^$StrLower("^%alphaitem%")$

          ^!Set %Count%=^%alphalist0%
          ^!Set %emer_exit%=^%Count%
          ^!Inc %emer_exit% 4
          ^!Set %Index%=0
          :alpha2num
          ^!Inc %Index%
          ^!If ^%Index% > ^%emer_exit% message
          ^!IfSame "^%alphaitem%" "^%alphalist^%Index%%" alpha2digit
          ^!Goto alpha2num

          :alpha2digit
          ^!Set %MM%=^%Index%
          ^!Set %length%=^$StrSize("^%MM%")$
          ^!If ^%length% => 2 skip
          ^!Set %MM%=0^%MM%
          ^!Goto finaloutput
          :message
          ^!Info emergency exited due to no alpha match^pwrong input
          ;---<end_of_clip---

          --
          Alan.
        • Alan
          ... In the effort to create/build, I d copied parts from others of my clips, pasted in, then modified to suite the current clip writing in progress. Due to
          Message 4 of 9 , Sep 5, 2004
          • 0 Attachment
            Alan C. wrote:
            > On Fri, 03 Sep 2004 15:48:59 -0700, Alan wrote:
            >> Hi,
            > [ snip ie see my former post for it has the date-manip clip that's talked about next ]

            In the effort to create/build, I'd copied parts from others of my clips,
            pasted in, then modified to suite the current clip writing in progress.

            Due to that as well as it's not good practice to have a variable that
            never gets used . . .. Of course, it does works fine as it was/is. But
            for those who would opt to change it, then:

            ^!Set %Count%=^%alphalist0%
            ^!Set %emer_exit%=^%Count%
            ^!Inc %emer_exit% 4

            Those above three code lines could be removed and then the next two code
            lines inserted as a replacement (%Count% never gets used except to dump
            off into %emer_exit%).

            ^!Set %emer_exit%=^%alphalist0%
            ^!Inc %emer_exit% 4

            ; ---end--

            BTW: Sometimes during creating a clip I don't get my thinking modified
            fast enough (so as to keep up with what it is that I'm doing). IOW, I
            need visual aid.

            So, the scramble to quickly get from clip idea, get the idea down and
            out in front of me in the editor so that I can see it. (idea retention
            can come and go, sometimes rather quickly, like birds in flight coming
            and going). Though I haven't yet, I guess I could speak it (the idea)
            into a cassette tape for subsequent perusal if needed.

            Yes, psuedo code is good. So is "chunking it down" (dividing the big up
            into smaller pieces) then do a piece at a time.

            --
            Alan.
          • prlproductmanager
            This works great. Thank you so much!!! Rayellen ... output ... of clip ... (procalphaitem). this proc re loops, iterates, comparing each month in alphalist to
            Message 5 of 9 , Sep 7, 2004
            • 0 Attachment
              This works great.
              Thank you so much!!!

              Rayellen

              --- In ntb-clips@yahoogroups.com, "Alan C." <acumming@c...> wrote:
              > On Fri, 03 Sep 2004 15:48:59 -0700, Alan wrote:
              > > Hi,
              > [ . . ]
              > >> For instance, in my doc, the date appears in any one of the
              > >> following formats:
              > >> March 01, 2004
              > >> MAR 1 2004
              > >> 03/01/2004
              > >> 03/01/04
              > >>
              > >> I can select the string, set the variable, but then I need to
              output
              > >> the date in 2 places in 2 different formats:
              > >> YYYY-MM-DD AND MM/DD/YYYY.
              >
              > The enclosed clip:
              > 1. puts 12 months into array (alphalist)
              > 2. replace each space with a /
              > 2b. replace , with nothing
              > 2c. puts the date string into a 3 item array (mdy)
              > 3. works/processes separately on each ie mdy1, mdy2, mdy3
              > 4. manipulates any and all digits during very first stage/section
              of clip
              > 5. soon then checks for an alpha string, checks for it on mdy1
              > 6. if not alpha string, then finaloutput real quick like
              > 7. or, if is yes alpha string then goto proc (process) alphaitem
              (procalphaitem). this proc re loops, iterates, comparing each month
              in alphalist to mdy1 (really at that point mdy1 is or has become:
              mdy1 > alphaitem > MM). if yes, a match, then substitutes the
              correct digit replaces the alpha. or, if not a match (foreign
              calendar item, etc.) then emergency exits the loop, goes to error
              message at bottom of clip.
              > --
              > March 01, 2004
              > MAR 1 2004
              > 03/01/2004
              > 03/01/04
              > October 03, 2004
              > gaf 04, 2004
              >
              > from those, select a line, try the clip if you like.
              > the next clip also works if select that gaf month line there :-)
              > (Well, ya never know - a Martian calendar might have or use
              something like that) :-)
              > longest clip line equals 59 characters. Clip enclosed next.
              >
              > H="date-manip"
              > ^!clearvariables
              > ^!Set %Date%=^$GetSelection$
              > ^!Set %Date%=^$StrReplace(" ";"/";"^%Date%";0;0)$
              > ^!Set %Date%=^$StrReplace(",";"";"^%Date%";0;0)$
              >
              > ^!Append %alphalist%=jan;feb;mar;apr;may;jun;jul;aug
              > ^!SetArray %alphalist%=^%alphalist%;sep;oct;nov;dec
              >
              > ^!SetListDelimiter /
              > ^!SetArray %mdy%=^%Date%
              > ; ^!Info ^%mdy1%~^%mdy2%~^%mdy3%
              >
              > ^!Set %DD%=^%mdy2%
              > ^!Set %length%=^$StrSize("^%DD%")$
              > ^!If ^%length% => 2 skip
              > ^!Set %DD%=0^%DD%
              >
              > ^!Set %YYYY%=^%mdy3%
              > ^!Set %length%=^$StrSize("^%YYYY%")$
              > ^!If ^%length% => 4 skip
              > ^!Set %YYYY%=20^%YYYY%
              >
              > ^!IfTrue ^$IsAlpha("^%mdy1%")$ procalphaitem
              > ^!Set %MM%=^%mdy1%
              >
              > :finaloutput
              > ^!Info ^%YYYY%-^%MM%-^%DD%^p^%MM%/^%DD%/^%YYYY%
              > ^!clearvariables
              > ^!Goto end
              >
              > :procalphaitem
              > ^!Set %alphaitem%=^$StrCopyLeft("^%mdy1%";3)$
              > ^!Set %alphaitem%=^$StrLower("^%alphaitem%")$
              >
              > ^!Set %Count%=^%alphalist0%
              > ^!Set %emer_exit%=^%Count%
              > ^!Inc %emer_exit% 4
              > ^!Set %Index%=0
              > :alpha2num
              > ^!Inc %Index%
              > ^!If ^%Index% > ^%emer_exit% message
              > ^!IfSame "^%alphaitem%" "^%alphalist^%Index%%" alpha2digit
              > ^!Goto alpha2num
              >
              > :alpha2digit
              > ^!Set %MM%=^%Index%
              > ^!Set %length%=^$StrSize("^%MM%")$
              > ^!If ^%length% => 2 skip
              > ^!Set %MM%=0^%MM%
              > ^!Goto finaloutput
              > :message
              > ^!Info emergency exited due to no alpha match^pwrong input
              > ;---<end_of_clip---
              >
              > --
              > Alan.
            Your message has been successfully submitted and would be delivered to recipients shortly.