• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Can't Coerce String to Date?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can't Coerce String to Date?


  • Subject: Can't Coerce String to Date?
  • From: Alex Hall <email@hidden>
  • Date: Fri, 13 Mar 2015 11:37:36 -0400

Hi list,
The reason is kind of long, but suffice it to say that when I need a date in a script, it has to be in a dictionary format so I can pull out specific pieces. To do this, I have a handler that takes a date object and hands me my dictionary. Using NSDates is causing problems, though. NSDateFormatter isn't really an option, again because of the way this script works and what it does, and it seems a waste to set up NSDateComponents (not to mention I can't figure out how to OR together the masks to get the information I want).

Now that my newest script uses NSDates, I'm trying to give those to this handler. Of course it won't work directly, so I need to put the NSDate into the AppleScript date type. I thought it would be easy:

set startDateString to (e's startDate()'s |description|()) as text
set startDate to (word 2 of startDateString & "/" & word 3 of startDateString & "/" & word 1 of startDateString) as date

In that snippet, "e" is an EKEvent. I don't get an error requesting e's date; rather I get an error that "can't convert "03/20/2015" to date". Yet, according to Google, AS can easily convert a string like that. The time will be midnight, but I can add the time in once this part is working. What am I doing wrong, or did something change because I'm using Yosemite and/or scripting additions?

--
Have a great day,
Alex Hall
email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Can't Coerce String to Date?
      • From: Shane Stanley <email@hidden>
    • Re: Can't Coerce String to Date?
      • From: Yvan KOENIG <email@hidden>
  • Prev by Date: Re: Resource for Cocoa Object Syntax in AS?
  • Next by Date: Re: What Does Error Return ?
  • Previous by thread: Re: integrating AppleScript and ScriptUI in Adobe Illustrator/InDesign?
  • Next by thread: Re: Can't Coerce String to Date?
  • Index(es):
    • Date
    • Thread