Getting chosen date from NSDatePicker

Hi all,

I am trying to get the chosen date from a date picker, at the moment I have got…


set chosenDate to (content of control "datePicker" of box "newTaskBox" of tab view item "newTab" of tab view "tabber" of window "mainWindow" as string)

which gives me somthing like ‘Friday, October 8, 2006, 05:44:47’

but I need it like 8/10/2006, as I need to convert it to julian for inserttion into a database

Is there a way of getting just the day, month and year seperatly?

thanks in advance.

The problem in your code is that the first thing you do as soon as you get it’s value is coerce it to a string. The ‘content’ of a datepicker is a date object, which has a well-supported set of applescript commands. Leave it as a date and use applescripts date commands to get various values and do coercions. Here are some basics…

set theDateInput to content of _DatePicker

set content of _DateString to (theDateInput as string)

set tmpNumDate to (((month of theDateInput) as integer) & "/" & (day of theDateInput) & "/" & (year of theDateInput)) as string
set content of _NumDateString to tmpNumDate

set content of _Month to (month of theDateInput) as string
set content of _NumMonth to ((month of theDateInput) as integer) as string
set content of _NumDay to (day of theDateInput) as string
set content of _Year to (year of theDateInput) as string

The apple date doc has a list of relavent date commands and capabilities.

j

Brilliant, thanks for your reply, going to play around with it a little now…

You could also use something like this:


set theDate to contents of control "date" of window "main"
set theShortDate to short date string of (theDate as date)

short date string depends on your settings (under International in System Preferences).