How to get current date without pipes?

tell current application
	current date
		--> date "ThuMay 20, 2010 | May 20 | 5:31:14 PM"
end tell

Is there a good way to get the date in a different format? Ideally something like “2010.05.20_5-31-14_PM”

It’s just the format for your computer. My computer returns the default setting (because it is default) and I got “date “Thursday, May 20, 2010 6:19:00PM””

I know there is a way to get the date in another format via command line.

Here’s one I expanded from a script by Nigel Garvey and with a bow to Kai Edwards as well:

makeTimeStamp((current date), ".")
--> "10.05.20.21.32.18". Its year, month, hour (24-hour clock), minute, seconds

-- aDelim should be one character of text
to makeTimeStamp(aDate, aDelim)
	-- Get our pieces
	tell aDate to set {yr, mo, dy, hr, mn, sc} to {its year, its month as number, its day, its hours, its minutes, its seconds} -- AppleScript understands assigning values to list items, and "telling" aDate enables us to use "its" in place of "of aDate" in every entry.
	-- Build our stamp
	set TS to "" -- initialize our output string to an empty string
	--return {yr, mo, dy, hr, mn, sc} -- uncomment to see the values of the parts
	repeat with D in {yr, mo, dy, hr, mn, sc} -- adjust each of the parts to be two characters
		if length of ((contents of D) as text) < 2 then set contents of D to "0" & D -- stick a "0" in front of single.
		set TS to TS & D & aDelim -- add this piece to the rest (called concatination)
	end repeat
	return characters 3 thru -2 of TS as string -- skip the "20", and the final "aDelim character".
end makeTimeStamp

You can alter the delimiters in the code itself – I’ve used all periods.

Thanks guys. Didn’t realize I had customized the format a long time ago.

Shortest way


set timeStamp to do shell script "/bin/date +%Y.%m.%d_%H-%M-%S_%p"

I’d just like to dissociate Kai and myself from that ‘return’ line. :wink: