Here is my version on the subject:
A little function that utilizes awk, to rearrange the date. Probably adding any value, since the other solutions here are more complete, just showing an alternative.
set fn to "23-02-2013"
set nf to isodate for fn
log fn
--> 2013-02-23
to isodate for theDate
set res to (do shell script "/usr/bin/awk 'BEGIN{FS=\"-\"}{print $3\"-\"$2\"-\"$1}' <<<" & theDate)
return res
end isodate
With pure Applescript you can really do it as simple as this:
set fn to "23-02-2013"
set nf to word 3 of fn & "-" & word 2 of fn & "-" & word 1 of fn
--> "2013-02-23"
Here we optimize a little bit for speed, since we make one reference to the filename, which we reference implicitly. This caters for that we don’t have to send the events the whole way every time we want something from fn.
set fn to "23-02-2013"
tell fn
set nf to word 3 & "-" & word 2 & "-" & word 1
end tell
--> "2013-02-23"
We can even optimize this further, like kel1 did, so that we don’t have to scan fn for word’s more than once, cutting down on the number operations, which is always a good thing to do, as long as one remember that the number of bugs is proportional to the number of statements.
set fn to "23-02-2013"
tell (words of fn)
set nf to item 3 & "-" & item 2 & "-" & item 1
end tell
--> "2013-02-23"
The terse version goes like this: Here we really do everything that we did before, but just in one line, we get the reversed list back, and lets Applescript assemble it for us by using text item delimiters. We set back the text item delimiters to their original value afterwards. This approach may be more inefficient than the one above, since we are using more assignements, but on the other hand we aren’t scanning for words. If one are to create new names for many folders, and keeps the statements that sets the text item delimiters outside that loop. Then this will be more efficient. Also: text items are more efficent in this case, since we are only looking for one delimiter, but splitting input into words, involves looking for many word-breaking characters, until we have the result set that consists of the list of words in the given input.
set fn to "23-02-2013"
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "-"}
set nf to reverse of (text items of fn) as text
set AppleScript's text item delimiters to tids
”> 2013-02-23
I think the absolutely fastest version would be as below: (when performing for many, and keeping the text item delimiters outside the loop).
Here we make Applescript assemble the parts of the new file name for us with the text item delimiter behind the scene, we don’t perform a list reversal, but address the elements directly.
set fn to "23-02-2013"
set {tids, text item delimiters} to {text item delimiters, "-"}
tell (text items of fn)
set nf to {text item 3, text item 2, text item 1}'s text as text
end tell
set text item delimiters to tids
--> 2013-02-23