• 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: Ed Stockly <email@hidden>
  • Date: Tue, 4 Dec 2007 21:56:07 -0800



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

--Set variable for default to current date plus one day
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
--Can't make {86412, "/", 86404, "/", 88407} into type string

Actually what it's telling you is it can't coerce a list of integers and strings into a string.

The integers are the result of adding numbers to a date.

--try these commands
-------------
set TomorrowDate to ((current date) + 1 * days)

display dialog (weekday of TomorrowDate as string) & ", " & ((month of TomorrowDate as integer) as string) & "/" & day of TomorrowDate & "/" & year of TomorrowDate
display dialog date string of TomorrowDate
-----------
Keep in mind that the date string uses the format for dates set on the user's international preferences, so building the date string from it's parts will give you more consistent results across different setups



Ummm...thanks. I was trying to parse the parts so that they would  display in a text string.


Yes, that's a good approach. I use it all the time.

 I  don't know what resource to go to for finding the right commands and  syntax to use.


This list is the best resource. Sometime some of the answers can seem a bit snarky, but overall this is the best place to go for AppleScript questions.


Date strings/fields/variables are handled differently than text-only  strings/fields/variables. So...I needed a way to try turning it into  "text" parts...which I said didn't work. Neither did the simpler  version.


The date value is an integer that records the number of seconds from some pre-determined date.  When you execute a date command (current date, month, etc) the integer is coerced into a familiar data format. 

You'll notice the month value needs to be coerced to an integer to avoid getting the name of the month.

Here's a scripting tip, in Script Editor open the apple even log and then use the log command to reveal information about variables.

For example:

set myValue to month of (current date)
log myValue
set myValue to myValue + 1* days
log class of myValue
log myValue
Here's what you would see in 
(*December*)
(*integer*)
(*86412*)

HTH

ES





=
 _______________________________________________
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

  • Prev by Date: Two mail.app applescript bugs
  • Next by Date: Re: Wow, AppleScript is tough!
  • Previous by thread: Re: Another question on dates and times
  • Next by thread: Re: Another question on dates and times
  • Index(es):
    • Date
    • Thread