Re: Converting Date?
Re: Converting Date?
- Subject: Re: Converting Date?
- From: has <email@hidden>
- Date: Tue, 27 Aug 2002 11:36:58 +0100
Jacki Barineau wrote:
>
For example, the following code in AppleScript:
>
>
as text
>
>
Returns the following:
>
>
Monday, August 26, 2002 12:28 AM
I'd suggest leaving off the 'as text' coercion here and get the value as a
date object. It's simpler and more robust to get the properties of the date
object and assemble your date string from those, than by chopping up a
string [see other thread on date formatting]. For example:
======================================================================
set message_date to time sent of message i of folder "Workshop
[NO-BREAK]Notification List" of folder "OO Mail" of folder "Inbox"
set entry_date to ((month of message_date) as string) & " " & day of
[NO-BREAK]message_date & ", " & year of message_date
======================================================================
>
The following script code:
>
>
set entry_date to words 2 through 4 of message_date
>
>
Returns the following:
>
>
August: 26: 2002
>
>
Is there a way to either have the script bring in the correct date format to
>
begin with or to somehow edit the returned string to remove the ":"'s and
>
put the "," after the day number...?
This is one of those problems where it's best to execute the code a line at
a time to see what's actually going on. There's a couple things happening
here: "words 2 through 4 of message_date" will actually return a list,
{"August", "26", "2002"}. This list is being implicitly coerced to a string
somewhere further on in your script. The ": " added between each word will
be due to your text item delimiters being set to this value.
But unless you're used to this sort of thing then none of it is obvious
just from looking at the code, which is why testing a line at a time is so
useful: you'll get fewer unexpected surprises if you can see for yourself
exactly what each line is doing. (Editors like Smile and Script Debugger
have various tools that let you watch what's going on as the script runs;
Script Editor users can always put in temporary 'log [variable name]' (1)
or 'return [variable name]' lines to see what's going on.
Incidentally, the expression you were after is:
set entry_date to text (word 2) through (word 4) of message_date
which will return a string containing all text from word 2 to word 4 of
message_date. Though I still recommend you use the first approach I
described, not this one; the rest of this explanation is more just for your
interest/future reference.
HTH
has
(1) SE logs to the Event Log window, so you'll need to have this open
before running your script.
_______________________________________________
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.