• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Another question on dates and times
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Another question on dates and times


  • Subject: Re: Another question on dates and times
  • From: Chris Page <email@hidden>
  • Date: Tue, 04 Dec 2007 21:26:00 -0800

On Dec 4, 2007, at 6:38 PM, Clint Hoxie wrote:

Anyway, I am getting an error which looks to be telling me that a date can't be returned as a string.

When asking questions about errors, it helps if you paste the actual error message.

set TomorrowDate to (month of (current date)) + 60 * 60 * 24 & "/" & (day of (current date)) + 60 * 60 * 24 & "/" & (year of (current date)) + 60 * 60 * 24

display dialog "Enter event date:" default answer TomorrowDate

The error is: “Can’t make {86412, "/", 86404, "/", 88407} into type string.”

You can't turn a list into a string unless all the items are strings. You need to convert the numbers to strings.

When you concatenate using “&” and the first item is a string, then AppleScript will attempt to convert the next object you concatenate to a string and concatenate the strings together:

  "/" & 12
  => "/12"

but if the first item before “&” is not a string, you get a list of the objects being concatenated together:

  12 & "/"
  => {12, "/"}

That is, the type of the left-hand side object determines how the two objects are concatenated together. In your case, you've concatenated to a number, which isn't what you want to do.

There are two solutions:

1. You can explicitly convert the numbers to strings with “as string”. In fact, you only have to do this for the first number, because once it's converted to a string, the subsequent concatenations of numbers will attempt to convert them to strings:

 (12 as string) & "/" & 11
 => "12/11"

or you can start building your string by concatenating to an empty string, e.g.:

  "" & 12 & "/" & 11
  => "12/11"

And then you'll notice that you're doing date math incorrectly (your math produces "86412/86404/88407") and you'll want to read the other replies on this thread to learn how to correct that.

-- 
Chris Page
The other, other AppleScript Chris
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Another question on dates and times
      • From: Chris Page <email@hidden>
References: 
 >Another question on dates and times (From: Clint Hoxie <email@hidden>)

  • Prev by Date: Re: Another question on dates and times
  • Next by Date: Re: Another question on dates and times
  • Previous by thread: Re: Another question on dates and times
  • Next by thread: Re: Another question on dates and times
  • Index(es):
    • Date
    • Thread