Working With Dates

Hello,

Does anyone know how I could change this string “2007-08-08” into an actual date.

Ex Change “2007-08-08” to Wednesday, August 8th, 2007. I need to be able to do it for any date. What I am trying to accomlish is to get applescript to automatically figure out that August 8th, 2007 was a Wednesday.

Any help would be greatly appreciated.

Thanks
Dallas

Hi Dallas,

"2007-08-08" as «class isot» as date

Holy crap that was fast,

Thanks Stefan.

What is «class isot» ?

Dallas

grr Stefan LOL

though your way better than the 3 liner I did :stuck_out_tongue:

nice to have you back, James :slight_smile:

Good to be back Stefan =)

ISO 8601 is an international standard for date and time representations

Thanks again Stefan

I am having a problem now, I dont know what the deal is.

Using the “as «class isot» as date” works great except for when I use the following code. I can’t figure out what’s wrong with these statements. I am parsing an XML to extract the date which returns the following “2007-08-08T00:00:00” but when it gets to the last statement I get an error message that says “Can’t make “2007-08-08T00:00:00” into type «class isot»”


tell application "System Events"
	set xml_file to choose file
	set xml_file_string to xml_file as string
	set F to XML file xml_file_string
	-- <dataroot>
	set root to XML element 1 of F
	set air_date to XML element 1 of root
	set air_date_extract to value of XML element 10 of air_date
end tell
set converted_air_date to air_date_extract as «class isot» as date

Thanks
Dallas

http://bbs.applescript.net/viewtopic.php?pid=79003#p79003

Unicode text won’t coerce properly (which is likely what you’re getting from the XML file). Try something like this:

set air_date_extract to "2007-04-10T18:56:00" as Unicode text -- example

set {text:converted_air_date} to (air_date_extract as string)
set converted_air_date to converted_air_date as «class isot» as date

See also: Convert Unicode Text to Plain Text

That did it Bruce, I have no idea why it worked so I am going to have to read the article you posted.

Thanks for your help as always.
Dallas

Something more to it than you think because by itself, this works:

"2007-08-09T22:22:15" as «class isot» as date

and class isot is forgiving as well:

"2007-08-09 22:22:15" as «class isot» as date

space instead of T.