DateA complete Date value specifies the day of the week, the date (month, day
of the month, and year), and the time; if you provide only some of this information, AppleScript fills in the missing pieces with default values. You
can get and set properties of a Date value that correspond to different parts
of the date and time information.
You can specify Date values in many different formats. The format always begins with the word
datefollowed by a string (within quotation marks) containing the date and time information. You can spell out the day of the week, month, or date. You can also use standard three-letter abbreviations
for the day and month.
LITERAL EXPRESSIONSdate "12/5/54, 12:06 PM" date "12/05/53, 12:06" date "12/05/54" date "12:06" date "Sunday, December 5, 1954 12:06 pm"
- The class identifier for the object. This property is read-only, and its value is always
- One of the constants
- One of the constants
- An integer specifying the year; for example,
- An integer that specifies the number of seconds since midnight of the date value; for example,
2700is equivalent to 12:45 AM.
- A string that consists of the date portion of the date value; for example,
"June 3, 1993".
OPERATORSThe operators that take Date values as operands are &, +, -, =, �, >, �, <, �, Comes Before, Comes After, and As. In expressions containing >, �, <, �, Comes Before, or Comes After, a later time is greater than an earlier time. The following operations on Date values with the + and - operators are supported:
date + timeDifference --result: date date - date --result: timeDifference date - timeDifference --result: datewhere date is a Date value and timeDifference is an Integer value specifying a time difference in seconds. To simplify the notation of time differences, you can also use one or more of these of these constants:
Here's an example:
- 60 * minutes
- 24 * hours
- 7 * days
date "Apr 15, 1992" + 4 * days + 3 * hours + 2 * minutesFor more information about the way AppleScript operators treat Date values, see "Date-Time Arithmetic," which begins on page 180.
REFERENCE FORMSYou can refer to properties of a Date value using the Property reference form.
weekday of date "May 3, 1993" --result: Monday time of date "May 3, 1993" --result: "12:00 AM"Note that AppleScript fills in a default time property for the date specified in the second example.
If you want to specify a time relative to a date, you can do so as follows:
date "2:30 am" of date "May 3, 1993" --result: date "May 3, 1993 2:30 AM" date "Sept. 27, 1993" relative to date "3PM" --result: date "September 27, 1993 3:00 PM"In addition to
of, you can also use the synonyms
COERCIONS SUPPORTEDAppleScript supports coercion of a Date value to a single-item list or a string.
NOTESRegardless of the format you use when you type a date in a script, AppleScript always displays Date values in the format shown in the following example, which includes the full name of the day of the week and month and no leading zeros for the date.
date "Sunday, January 3, 1992 12:05 PM"If you don't specify a complete date, day, and time when typing a Date value, AppleScript fills in information as needed. If you don't specify the date information, AppleScript uses the date when the script is compiled. If you don't specify the time information, 12:00 AM (midnight) is the default. If you omit AM or PM, AM is the default; however, if you specify 12:00 without AM or PM, 12:00 PM is the default. If you specify the time using 24-hour time, AppleScript converts it to the equivalent time using AM or PM; for example, 17:00 is equivalent to 5:00 PM.
To get the current date, use the scripting addition command Current Date.
if current date = date "Sunday, January 23, 1992 12:05 PM" then print the front window end ifFor a complete description of the Current Date command, see the AppleScript Scripting Additions Guide.