Re: Applescript can't tell time?
Re: Applescript can't tell time?
- Subject: Re: Applescript can't tell time?
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 03 Feb 2004 10:03:56 -0800
On 2/3/04 9:01 AM, "Robert Poland" <email@hidden> wrote:
>
Why doesn't this script work?
>
>
set nowDate to (current date)
>
set nowTime to "" & time string of (nowDate)
>
set bedTime to "8:59.00 PM" as text --> "8:59.00 PM"
>
set nowTime to nowTime as text --> "9:57:26 AM"
>
if (nowTime is less than bedTime) then
>
set x to 1
>
else
>
set x to 2
>
end if
>
x --> 2
>
You're doing string comparisons, not time or number comparisons. (And, BTW,
'time string' is already a string so ' "" & time string' does nothing.
Similarly "8:59.00 PM" already is text, so 'as text' does nothing.) You're
also using a period instead of a colon in "8:59.00 PM" which could muddle
things if the hour and minutes were the same.
Doing a string comparison "9xxxxxx" is always going to be "greater" than
"8xxxxxx". AM and PM , or XM or piddleM at the end won't affect anything.
What you need use a time (integer) comparison:
set nowDate to (current date)
set today to date string of nowDate
set bedTime to date (today & " 8:59.00 PM")
if (nowDate is less than bedTime) then
set X to 1
else
set X to 2
end if
--> 1
--
Paul Berkowitz
_______________________________________________
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.