Date

A date is a date-time. For the practical limits on the range of dates that can be expressed, see the year property later in this section. AppleScript knows nothing of time zones, and assumes the Gregorian calendar even for dates before its invention.

A literal date is an object string specifier (see Chapter 10). In constructing a date, you may use any string value that can be interpreted as a date, a time, or a date-time; AppleScript (or more probably the System) is quite liberal in what it will accept, provided the string makes sense in terms of your date and time format settings in the International pane of System Preferences. AppleScript will supply missing values such as today’s date (if you give only a time) or this year (if you don’t give a year) or midnight (if you give only a date).

AppleScript presents a literal date specifier in long date-time format in accordance with your International settings. It does this even within your script, on decompilation, if you use a literal string in a date specifier:

date "5/25/2003" -- rewritten: date "Sunday, May 25, 2003 12:00:00 AM"

If the expression "5/25/2003" isn’t a date according to your International preferences, this code won’t compile. For example, if you have UK settings, you’d need to type date "25/5/2003“.

Having obtained a date one way or another, you can then derive a new date from it in two ways. One is by date arithmetic, which involves adding and subtracting seconds. (See Chapter 15 and Chapter 17 for some constants ...

Get AppleScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.