Work with dates and times
- Last Updated: January 22, 2026
- 4 minute read
- OpenEdge
- Version 12.8
- Documentation
You can define three types of date- and time-related data in your application:
| ABL data type | Description |
|---|---|
| DATE | A value that represents a date using the Gregorian calendar. |
| DATETIME | A value that consists of an ABL DATE type and the time in milliseconds starting at midnight on that date. |
| DATETIME-TZ | A value that consists of an ABL DATETIME type and the time zone offset from Coordinated Universal Time (UTC) in minutes. The format of the time zone offset is hours and minutes. |
The default initial value for these types is the Unknown value (?). If you attempt to write or display a date that was not
assigned a value, then it is written or displayed as a blank.
If you share a DATE or DATETIME value with another process, you must take into consideration time zone information and how system time is calculated on different platforms.
Example date and time formats
| ABL type | Format specification | Sample output |
|---|---|---|
| DATE | mm/dd/yy (Default)
|
05/30/20 05/30/2020 05-30-20 |
| DATETIME | mm/dd/yyyy HH:MM:SS.SSS (Default)
|
05/30/2020 15:30:44.234 05/30/2020 15:30 05-30-2020 03:30:44 pm |
| DATETIME-TZ | mm/dd/yyyy HH:MM:SS.SSS+HH:MM
(Default)
|
05/30/2020 16:30:44.234-03:00 5/30/2020 16:30-03:00 |
Define and initialize date and time variables
To initialize a DATE, DATETIME, or DATETIME-TZ variable, you must specify a value that matches the type of data you want to initialize. The specification of a DATETIME or DATETIME-TZ initial value that contains spaces requires quotation marks around it. You do not need to use quotation marks for the initial value of a DATE type or if specifying a DATETIME in ISO date/time format.
The following example code defines a variable of each of the ABL date and time types.
|
Date and time operators and functions
ABL provides operators and built-in functions for working with dates and times.
The following example code uses several of these operators and functions:
|
Running the example code produces output similar to the following:
|
Format and display dates
This example demonstrates how to format today’s date as dd/mm/yyyy using the
STRING() function and display it with the
MESSAGE statement.
|
Running this code produces output similar to the following:
28/07/2025 |
Set the display order for dates
The default order for displaying date
information is month, followed by day, followed by year (mdy). You can change the
default order by specifying the Date Format (-d) startup parameter (for
example, -d dmy or -d
ydm). In addition, you can temporarily change the display order for the
current session by setting the DATE-FORMAT
attribute on the SESSION system handle. (You learn
more about handles in Work with handles.)
The following example code displays the current date (using the
TODAY function) and date and time (using the
NOW function). The date display order is then
changed to dmy for the current ABL session. The
current date and time are then redisplayed.
|
|
|
Calculate intervals with dates and times
You can calculate intervals between two dates and times using the INTERVAL function. When you use this function, the
types of the two variables do not need to be the same. You provide two DATE,
DATETIME, or DATETIME-TZ values, and the function subtracts the milliseconds in the
second value from the milliseconds in the first value. The value returned is in the
units of the interval type you requested.
INTERVAL function is
shown:
|
dtVal1- The first DATE, DATETIME, or DATETIME-TZ value.
dtVal2- The second DATE, DATETIME, or DATETIME-TZ value.
interval-type- Can be any of the strings: "years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds".
In the following example code, the INTERVAL
function requests the number of days between dtShipDate and dtOrderTime.
|
Running the code produces the following output:
|