Date and Time Values in SenseTalk
SenseTalk includes commands and functions for working with dates and times. One date or time can be subtracted from another by using the minus ( - ) operator, to get their difference in seconds. A time interval can also be added to a date or time to obtain a new date/time value (see Adding and Subtracting Time Intervals).
Dates, Times, and Time Intervals
SenseTalk makes no fundamental distinction between a "date" and a "time"—both are treated as precise instants in the flow of time, or points along a timeline whose origin (zero value) was at the stroke of midnight at the beginning of January 1, 2001, Coordinated Universal Time. Any date or time before that instant is treated internally as a negative value, and later times as a positive value indicating the number of seconds since the origin.
SenseTalk can recognize dates and times expressed in a wide variety of formats such as "4/22/67" or "1967-04-22 18:00." See the timeInputFormat
global property for details. The Natural
format allows even more variations, such as "May 15, 2004 10:57 PM", or even "yesterday", "today", or "next Tuesday in the afternoon." The words today
and now
(without enclosing quotes) can be used to indicate the current date or the current date and time (unless they are used as variables and assigned some other value). See Natural
Format for more information about this format.
Whenever a date value is supplied without a time of day, it is taken to mean noon of that day. When a time is given without a date, it is assumed to mean the indicated time on the current date (today). All dates and times are assumed to be in the local time zone, as currently set on the machine where the script is running.
A time interval or duration is a length of time. When dealing with time intervals, SenseTalk assumes durations measured in seconds if no specific unit is given, but also allows many other units to be used including weeks, days, hours, milliseconds, etc. (see Time Intervals in Values).
In addition to durations that can be precisely measured in seconds, SenseTalk also supports calendar durations measured in months, including months, calendarQuarters, calendarYears, etc. To see the full list of calendarDuration units that are available, use this command:
put (each item of the unitNames whose unitType is calendarDuration) sorted
See Calendar Durations for more information.
Both time intervals and calendar durations can be used with the ago
and hence
operators to produce a time value that is a length of time in the past or future.
Because there is no real difference between dates and times, this document sometimes refers to either a date or a time as "a date/time value."
Related Global and Local Properties
SenseTalk includes several global or local properties that you can use to affect the behavior of date and time values in your scripts. You will see these properties mentioned in the descriptions of concepts below. Full definitions of each property can be found on Local and Global Properties for Working with Values. The specific properties are:
The ClockFormat
The TimeFormat
The TimeInputFormat
The CenturyCutoff
The LastDayOfMonthCalculation
Date/Time Arithmetic
Adding and Subtracting Time Intervals
Starting from any date (or time), you can obtain a different date/time by simply adding or subtracting a time interval.
Example:
put today + 2 weeks into dueDate
Example:
subtract 3 hours 14 minutes 22 seconds from timer