Re: Date object into FMP field
Re: Date object into FMP field
- Subject: Re: Date object into FMP field
- From: Andrew Oliver <email@hidden>
- Date: Thu, 11 Mar 2004 18:12:13 -0800
On 3/11/04 12:46 PM, "Gary (Lists)" <email@hidden> wrote:
>
-- // The script, with results along the way
>
>
set c to current date
>
-- date "Thursday, March 11, 2004 3:02:18 PM"
>
>
set cd to c as text
>
-- "Thursday, March 11, 2004 3:02:18 PM"
Only if your date preferences are set to US English. Other countries formats
will differ. You can not rely on 'words' of a 'date as string' for this.
This is why I said I needed a universal/portable solution.
Fortunately, AppleScript does provide some hints. You can, for example use
the 'month of (current date)' to get an AppleScript constant that represents
the current month, and you can also get 'day of (current date)' and 'year of
(current date)' to get numeric objects with the appropriate values.
>
>
set wd to word 1 of cd
>
-- "Thursday"
>
>
set md to words 2 thru 3 of cd
>
-- {"March", "11"}
>
>
set m to item 1 of md
>
-- "March"
>
>
-- use your own routine to get month number
>
if m is "March" then set m to "3"
>
-- "3"
>
>
set d to item 2 of md
>
-- "11"
>
>
set y to word 4 of cd
>
-- "2004"
>
>
{y, m, d}
>
-- {"2004", "3", "11"}
All the above depends on US English date formatting. Try setting your system
preferences to Swedish and see what you get.
>
>
set FMdate to m & "-" & d & "-" & y
>
-- or any other format you wish
>
-- "3-11-2004"
>
>
set cell "fDate" of current record to FMdate
>
>
-- // end
>
>
Nothing else is needed by FM.
Provided you're happy to live with the 'format as entered' limitation which
I'm not. There are just too many ambiguous ways to format a date to leave it
up to the user. At the very least you'll end up with some random selection
of month names and numbers in different records, and there's no way that
when you see "11/3/04" in a field you'll know whether it's November 3rd or
March 11 if you leave it up to users.
IMHO the only practical way of using dates in a Filemaker database used by
multiple users is to standardize on date formatting and not give users the
option.
Andrew
:)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.