[comp.sys.mac.hypercard] Sorting by Date in HyperCard

lih@cunixd.cc.columbia.edu (Andrew Lih) (09/18/89)

Hi, I have a question regarding sorting in HyperCard.

If I have a whole bunch of cards with a bkgd field that contains a
date in short format (6/9/89, for example), what is the best way to
sort this in chronological order?  Is there a way in HyperCard or has
anyone written an XCMD to do this?

Also, some of the dates are in the format (6-9-89) and some are
(6/9/89), what is the best way to convert the dashes to slashes?  Am I
going to have to write a script that does this? (ugh!)

Thanks for the help!

/lih
                 ___________________________________________________________
""""""""""     /							    \
|  @  @  |     | Andrew "Fuz" Lih	Columbia University Center           |
<    >   > ___/   Academic Computing	 for Computing Activities            |
 \ \__/ / <___                                                               /
  \____/      \    lih@cunixc.cc.columbia.edu    AJLUS@CUVMB.BITNET         /
	       \    lih@cs.columbia.edu     ...rutgers!columbia!cunixc!lih |
                \__________________________________________________________/

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 """""""   Andrew "Fuz" Lih	              Columbia University Center
 | @ @ |   Instructional Computing	      for Computing Activities
 <  ^  >					
  \ - /    lih@cunixc.cc.columbia.edu	      AJLUS@CUVMB.BITNET
   --- 	   lih@heathcliff.cs.columbia.edu  ...rutgers!columbia!cunixc!lih
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

american@pnet51.orb.mn.org (Jeff Iverson) (09/20/89)

lih@cunixd.cc.columbia.edu (Andrew Lih) writes:
>
>Hi, I have a question regarding sorting in HyperCard.
>
>If I have a whole bunch of cards with a bkgd field that contains a
>date in short format (6/9/89, for example), what is the best way to
>sort this in chronological order?  Is there a way in HyperCard or has
>anyone written an XCMD to do this?
>
>Also, some of the dates are in the format (6-9-89) and some are
>(6/9/89), what is the best way to convert the dashes to slashes?  Am I
>going to have to write a script that does this? (ugh!)
>
>Thanks for the help!
>
>/lih
>                 ___________________________________________________________
>""""""""""     /							    \
>|  @  @  |     | Andrew "Fuz" Lih	Columbia University Center           |
><    >   > ___/   Academic Computing	 for Computing Activities            |
> \ \__/ / <___                                                               /
>  \____/      \    lih@cunixc.cc.columbia.edu    AJLUS@CUVMB.BITNET         /
>	       \    lih@cs.columbia.edu     ...rutgers!columbia!cunixc!lih |
>                \__________________________________________________________/
>
>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> """""""   Andrew "Fuz" Lih	              Columbia University Center
> | @ @ |   Instructional Computing	      for Computing Activities
> <  ^  >					
>  \ - /    lih@cunixc.cc.columbia.edu	      AJLUS@CUVMB.BITNET
>   --- 	   lih@heathcliff.cs.columbia.edu  ...rutgers!columbia!cunixc!lih
>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

To do the sort, convert the contents of the field to seconds, then sort
numeric by that field, when the sort is done, convert the field to short date
which will give you all dates in the form xx/xx/xx with slashes instead of
dashes.

A sample script would be;

--In a sort button perhaps
on mouseup
  repeat with x = 1 to the number of cds
    go cd x
    convert fld "dateField" to secs
  end repeat
  sort numeric by fld "dateField"
  repeat with x = 1 to the number of cds
    go cd x
    convert fld "dateField" to short date
  end repeat
end mouseup

I'm sure there's a more elegant way to do this, but this gets it done.

UUCP: {amdahl!bungia, uunet!rosevax, chinet, killer}!orbit!pnet51!american
ARPA: crash!orbit!pnet51!american@nosc.mil
INET: american@pnet51.cts.com
GEnie:  APOSTASY
AppleLink:  ALL.AMERICAN
U. S. Mail:  All-American Software Development Corp.
             5612 International Parkway
             Minneapolis MN  55428
             Jeff Iverson

tecot@Apple.COM (Ed Tecot) (10/03/89)

In article <1102@orbit.UUCP> american@pnet51.orb.mn.org (Jeff Iverson) writes:
>lih@cunixd.cc.columbia.edu (Andrew Lih) writes:
>>If I have a whole bunch of cards with a bkgd field that contains a
>>date in short format (6/9/89, for example), what is the best way to
>>sort this in chronological order?  Is there a way in HyperCard or has
>>anyone written an XCMD to do this?
>
>To do the sort, convert the contents of the field to seconds, then sort
>numeric by that field, when the sort is done, convert the field to short date
>which will give you all dates in the form xx/xx/xx with slashes instead of
>dashes.
>
> [sample script omitted]

Dan Winkler sent me a simpler way to do this and asked me to post it to the
net:

	sort dateTime by field "dateField"