setting date of control

I have a date picker that I am trying to send a date to. I can figure it out when using current date. But if I want to send something that is not current date what format should I use? Example, if i want to send it a date of “01/04/2010” it does nothing.

	set content of control "date_picker" of window "main" to current_date

I think this should do it:

set myDate to date "23/12/2012"
set content of control "Date Picker" of window "Main" to myDate

or just

set content of control "Date Picker" of window "Main" to (date "23/12/2012")

Hope it works,

EDIT: Just a reminder, if you compile your script, the string “23/12/2012” is going to change into something like this: date “zondag, 23 december 2012 00:00:00”. If you want to keep the original, define your date like this:

date ("23/12/2012" as string)


the date picker expects a value of class date.
Consider that creating a date from a string depends on the international date format settings.

This works on an US system, but might give an unexpected result or throw an error on non-US systems

set d to "01/04/2010"
set AppleScriptDate to date d

Thanks StevenK, works great!

Who?? :wink:

My bad lol

Thank you StefanK, you are the best!

BTW, have another question posted. Sure its a simple answer for you and your huge knowledge base :slight_smile:

As of 10.6, building dates from strings has become even more unreliable, though. For example, your snippet now actually ignores my date format settings and uses the US settings.

It’s a bit more typing to do it the following way, but I reckon it’s worth the effort:

set thisDate to (current date) -- a starting date
set day of thisDate to 1 -- important
set year of thisDate to 2010
set month of thisDate to 1
set day of thisDate to 4