Date
A 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
date
followed 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 EXPRESSIONS
date "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"PROPERTIES
Class
- The class identifier for the object. This property is read-only, and its value is always
date
.Weekday
- One of the constants
Monday
,Tuesday
,Wednesday
,Thursday
,Friday
,Saturday
,Sunday
orMon
,Tue
,Wed
,Thu
,Fri
,Sat
,Sun
.Month
- One of the constants
January
,February
,March
,April
,May
,June
,July
,August
,September
,October
,November
,December
orJan
,Feb
,Mar
,Apr
,May
,Jun
,Jul
,Aug
,Sep
,Oct
,Nov
,Dec
.Year
- An integer specifying the year; for example,
1993
.Time
- An integer that specifies the number of seconds since midnight of the date value; for example,
2700
is equivalent to 12:45 AM.Date
- A string that consists of the date portion of the date value; for example,
"June 3, 1993"
.ELEMENTS
NoneOPERATORS
The 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:
minutes
- 60
hours
- 60 * minutes
days
- 24 * hours
weeks
- 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 FORMS
You 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 toof
, you can also use the synonymsrelative to
orin
for
this purpose.COERCIONS SUPPORTED
AppleScript supports coercion of a Date value to a single-item list or a string.NOTES
Regardless 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.
For example,
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.