Name
date
Allowed coercions
list with one item |
string
|
Syntax
set dateVar to date "January 1, 2000"
Description
You can use
strings to express several different forms of date
expressions. But AppleScript will not store the value as a
date
object unless you precede the
string
with the date
keyword:
set theDate to date "1/1/2000"
It is very easy to forget to include the date
keyword; if you leave it out, the variable will be set to a
string
and will not contain any of the
date
object’s properties (e.g.,
Time String
).
This example uses the current date scripting
addition to return a date
object. The script shows
the code’s return value within comment characters
(“(* *)”):
set theDate to current date (*date "Friday, November 12, 1999 8:22:11 AM" *)
Once you have a valid date
object, then you can
obtain the values of several properties from it:
- Class
date
- Date String
The date not including the time value (“Friday, November 12, 1999”)
- Day
An
integer
that represents the day of the month, as in 12 for “November 12”- Month
Represents one of the following constants:
January |
July |
February |
August |
March |
September |
April |
October |
May |
November |
June |
December |
- Time
An
integer
representing the number of seconds since midnight- Time String
Gets the time from the
date
object instring
form (“8:22:11 AM”)- Weekday
Stored in one of the following constants
:
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
Sunday |
- Year
An
integer
representing the year
If you create a date
object from a literal
string
, then ...
Get AppleScript in a Nutshell 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.