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: Walter Ian Kaye <email@hidden>
- Date: Tue, 18 May 2004 15:59:29 -0700
At 04:14p -0400 05/18/2004, Steven Valenti didst inscribe upon an
electronic papyrus:
I would like to find the oldest date in a list but just can't seem to
think how to evaluate all of the items. Can anyone help? The items in
this list are names of folders that were created in a backup script and
after 5 days I need to delete the oldest backup.
set BackUpFolder to {"5/11/2004", "5/12/2004", "5/13/2004",
"5/14/2004", "5/17/2004", "5/18/2004"}
Well, m/d/y format does not lend itself well to comparisons. (understatement;)
So, your first task is to put the date strings into a format which does.
Do you have any options for obtaining them in a better format, or are
you stuck with m/d/y and therefore need to change them each time?
yyyy-mm-dd is good for comparisons, as is a true date object.
You will have to loop through the list, and convert each date string
into a date object for comparison. Try this:
set BackUpFolder to {"5/11/2004", "5/12/2004", "5/13/2004",
"5/14/2004", "5/17/2004", "5/18/2004"}
set oldestDate to "12/31/2039"
repeat with ds in BackUpFolder
if MDYtoDate(ds) < MDYtoDate(oldestDate) then set oldestDate to ds as item
end repeat
oldestDate
on MDYtoDate(mdy)
set {m, d, y} to every word of mdy
set theDate to (current date)
set day of theDate to 1
set year of theDate to y
set month of theDate to item m of {January, February, March,
April, May, June, July, August, September, October, November,
December}
set day of theDate to d
theDate
end MDYtoDate
-Walter
_______________________________________________
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.