Dates and Time
A date is a real Otter value, not text. today gives the current date; now gives the current date and time.
Otter
date is today
started is now
A date and a date-time are different
today has no time of day at all — it is not midnight, it simply does not carry a time. now carries both a date and a time. This is a meaningful distinction, not a technicality: a date with "no time" and a date at "00:00:00" are not the same idea, so Otter does not pretend one is the other.
Because of that, asking a plain date for its hour, minute, or second is invalid rather than answering with a silent zero:
Otter
date is today
say hour of date
That fails when it runs, with an error explaining that this date has no time of day. Reach for now when you need a time as well as a date.
Reading the parts of a date
Date parts are read the same way any other property is read — with of, not with a period. Year, month, and day work on both a date and a date-time:
Otter
say year of date
say month of date
say day of date
month of date is always a number from 1 to 12, never a month name.
Hour, minute, and second work on a date-time such as started:
Otter
say hour of started
say minute of started
say second of started
Adjusting a date
Move a date forward with add, or backward with remove. Both the singular and plural spelling of a unit are accepted, so 1 day and 7 days both work:
Otter
add 7 days to date
remove 1 month from date
The same words work on a date-time, down to the second:
Otter
add 1 hour to started
add 30 minutes to started
Formatting
format ... as ... into ... produces text. It does not change the date it was given:
Otter
format date as "MM/dd/yyyy" into text
say text
say date
The second say still prints the original date, untouched.
The difference between two dates
days between is an expression, so assign it with the same is form used for every other value:
Otter
startDate is date from "2024-01-15"
endDate is date from "2024-03-01"
waiting is days between startDate and endDate
say waiting
The expression can also be used directly wherever a value is expected:
Otter
startDate is date from "2024-01-15"
endDate is date from "2024-03-01"
say days between startDate and endDate
The older days between ... make ... statement remains accepted for compatibility, but new programs should prefer the expression form.
The result is signed, computed as end minus start:
- positive — endDate is later than startDate
- zero — the two are the same, at the precision asked for
- negative — endDate is earlier than startDate
Comparing dates
Dates compare with the same words as any other value — there is no separate date-comparison syntax:
Otter
startDate is date from "2024-01-15"
endDate is date from "2024-03-01"
if endDate is greater than startDate
say "The end date is later."
.
How a date prints
say prints a date-only value like this:
Otter
say today
Example output: 2026-09-09
and a date-time value like this:
Otter
say now
Example output: 2026-09-09 14:30:05
Not part of this version
There is no timezone syntax — a date is always in local time. There is no month-name syntax; month of date is always a number.