Searching a string between two reference points [date]

Hi,
I’m sure this is simple but I need some help anyway. I’m using Applescript’s “current date” comand but I only want a portion of the string. i.e Friday, March 30, 2007 15:54:07 but I only need March 30, 2007 section of text. I know I can’t count the characters as in my example for thetimeprocessed below because the length of charaters in the month changes so the only thing I can think of doing is searching between the first “,” and characters -10 any idea of how to do this or a better way of handling this?
Thanks for your time

set thedate to (current date) as string
set thetimeprocessed to characters -1 thru -8 of thedate as string

You could just pull out the date pieces you need

set {M, D, Y} to {month, day, year} of (current date)

Hi, blend3.

Dates have a ‘date string’ property, which has the same format as the ‘date as string’ but without the time:

date string of (current date)

Similarly, you can get the time part without the date:

time string of (current date)

In all cases, the time and/or date is returned in the format set up in the user’s own International preferences.

Edit: Beaten x2! :stuck_out_tongue:

This should also work:

tell (current date) to set theDate to "" & month of it & " " & day of it & ", " & year of it

This would be better if you’re going to distribute this script to other people (it uses the International settings in System Preferences):

display dialog (date string of (current date))
-- or
display dialog (short date string of (current date))

Side note: characters as string is not the best method for you’re first example. First, it depends on AppleScript’s text item delimiters (because it creates a list and then coerces the list into text). Consider this:

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "~~BOO~~"
try
	set thedate to (current date) as string
	set thetimeprocessed to characters -1 thru -8 of thedate as string
end try
set AppleScript's text item delimiters to ASTID

display dialog thetimeprocessed

Also, it takes more resources than using text (text doesn’t involve a coercion like characters does):

set thedate to (current date) as string
set thetimeprocessed to text -1 thru -8 of thedate

Wow, Thanks everybody I didn’t realize there was so many options available for “current date” this has certainly answered my question.
Thanks again :smiley: