Re: Finding the oldest date in a list
Re: Finding the oldest date in a list
- Subject: Re: Finding the oldest date in a list
- From: Nigel Garvey <email@hidden>
- Date: Wed, 19 May 2004 10:29:14 +0100
Walter Ian Kaye wrote on Tue, 18 May 2004 16:33:20 -0700:
>
At 06:24p -0400 05/18/2004, Graff didst inscribe upon an electronic papyrus:
>
>
>For AppleScript prior to 1.9.0 you need this script:
>
>----
>
>set BackUpFolder to {"5/11/2004", "5/12/2004", "5/13/2004",
>
>"5/14/2004", "5/17/2004", "5/18/2004"}
>
>
>
>set oldestDate to date (item 1 of BackUpFolder)
>
>set dateList to rest of BackUpFolder
>
>
>
>repeat with textDate in dateList
>
> if (date textDate) < oldestDate then
>
>
For the record, (date textDate) does NOT work on my system, 10.2.8.
>
>
Well, it works with a literal string (date "5/11/2004"), but it
>
throws an error when used with a variable.
It isn't actually necessary to use AppleScript dates at all. A fast
method for a known short date format, which would work on any machine,
would be to use a sort of "month sum" for each date - ie. month + (day /
32) + (year * 12). For US-format short dates:
set BackUpFolder to {"5/11/2004", "5/12/2004", "5/13/2004",
"5/14/2004", "5/17/2004", "5/18/2004"}
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set earliestDateIndex to 1
tell text items of item 1 of BackUpFolder to set lowestSum to beginning
+ (item 2) / 32 + end * 12
repeat with i from 2 to (count BackUpFolder)
tell text items of item i of BackUpFolder to set thisSum to beginning
+ (item 2) / 32 + end * 12
if thisSum < lowestSum then
set lowestSum to thisSum
set earliestDateIndex to i
end if
end repeat
set AppleScript's text item delimiters to astid
set earliestDate to item earliestDateIndex of BackUpFolder
--> "5/11/2004"
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.