# Date Operators

#### Date Properties

Read/write properties allow various aspects of data/time data to be read or set.

Date.day (1-31)

Date.month (1-12)

Date.year (value of year)

Date.hour (0-23)

Date.minute (0-59)

Date.weekday (1-7) Monday = 1, Sunday = 7. Read-only

If the Date is `"never"`, all functions return 0 (zero). For example:

> `$Width = $DueDate.month`

> `$DueDate.day=1;`

#### Date Operators

Date.format("format-string") converts a date to a string, using the quoted date format string. For example, `$DueDate.format("l")` will format the value of $DueDate using the system’s short date format.

L: local time, in long format, using the system format settings (example: Tuesday, April 29, 2003.)

l: local time, in short format, using the system format settings (example: 4-29-03)

d: day of the month (example: 29)

D: formats date 01-31, with leading zero

m: number of month (example: 4)

M: abbreviation of month (example: Apr)

MM: name of month (example:April) w: abbreviation of weekday (example: Tue)

M0: formats month numerically 01-12, with leading 0

W: name of weekday (example: Tuesday)

y: year (example: 2003)

t: time, in local format (example: 2:32 pm)

h: hour of the day on a 24-hour clock (example: 13:39)

H: hour of the day on a 12-hour clock (example: 1:39)

mm: minute of the hour (example:05 for five minutes after the hour)

s: second

p: AM or PM

*: date/time in RFC 822 format (example: Thu, 18 Feb 2004 19:12:00 0500)

=: date in ISO 8601 format (example: 2004-02-18)

U: date as Unix epoch (seconds since 1 January 1970)

date(year,month,day,hour,min) constructs a date from individual numeric elements. This is useful, for example, if you need to assemble a date from separate attributes. year is the 4-digit year, month is a number from 1-12. The time arguments are optional, and are specified in a 24-hour clock.

> `date(2004,7,23,16,45)` is 23 July 2004 4:45pm

date("string") constructs a date from string which is a string literal or string expression. Usually, this is not necessary as Storyspace will coerce the string to a date type automatically. In some contexts, though, it may be more convenient or more clear to make the conversion explicit. (See format() to convert dates into strings)

#### Date/time comparison operators

days(date1,date2) returns the number of days that elapsed between date1 and date2, as a number. If date2 is the earlier date, the result is negative. The internal comparison includes the time portion of the date. thus if 2 dates are 1 day apart but the times are less than 24 hours aport, the result is 0 and not 1 as might be expected.

hours(date1,date2) returns the number of hours that elapsed between date1 and date2, as a number. If date2 is the earlier date, the result is negative.

minutes(date1,date2) returns the number of minutes that elapsed between date1 and date2, as a number. If date2 is the earlier date, the result is negative.

seconds(date1,date2) returns the number of seconds that elapsed between date1 and date2, as a number. If date2 is the earlier date, the result is negative.

months(date1,date2) returns the number of moths that elapsed between date1 and date2, as a number. If date2 is the earlier date, the result is negative.

years(date1,date2) returns the number of minutes that elapsed between date1 and date2, as a number. If date2 is the earlier date, the result is negotiatingative.

#### Locales

When converting between strings and dates, Storyspace uses a variety of formats including the date format used in your locale as specified in System Preferences:Language and Region.

When practical, you should adapt these preferences to your needs. In particular, if you frequently use historical dates, you should avoid formats with two-digit years.

The locale() action allows you to check your current locale setting and to change it. For example, if you are a Swedish historian working in Australia you might want the notes for your next article to use Swedish date formats with your task list might use Australian settings.