2.6. The Date Class

AppleScript is unique with its special class for working with dates. You can store dates inside variables in your program and then manipulate those dates to find things such as the number of days between two dates, the day of the week a particular day falls on, or a list of files created within the last seven days.

The general format for a date in AppleScript is as follows:

Weekday, Month day, year  hh:mm:ss ampm

where

Weekdayis the day of the week, with possible values of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, or Saturday
Monthis the month of the year, with possible values of January, February, March, April, May, June, July, August, September, October, November, or December
dayis the day number, with values from 1 through 31
yearis the four-digit year number
hh:mm:ssis the time expressed in hours, minutes, and seconds
ampmis AM, PM, or omitted if a 24-hour clock is being used

The following Try It Out gives you some practice in working with the format of a date in AppleScript.

2.6.1.

2.6.1.1. Try It Out: Understanding the Date Format

Follow these steps to work with the date format.

  1. Type the following program into Script Editor:

    current date
  2. Click the Result tab and run the program. Your result should look like the following except that your date will reflect when you run the program:

    date "Wednesday, September 22, 2004 6:29:10 PM"

If you have your International settings under System Preferences set to use a 24-hour clock (which you do by setting ...

Get Beginning AppleScript® 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.