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)

mm/dd/yyyy

mm-dd-yy

05/30/20

05/30/2020

05-30-20

DATETIME mm/dd/yyyy HH:MM:SS.SSS (Default)

mm/dd/yyyy HH:MM

mm-dd-yyyy HH:MM:SS am

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)

mm/dd/yyyy HH:MM+HH:MM

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.

VAR DATE dtShipDate = 02-14-2020.
VAR DATETIME dtShipTime = "02-14-2020 14:45".
VAR DATETIME-TZ dtOrderTime = "12-17-2020 10:15-5:00".
Note: The date and time part of a DATETIME-TZ is stored relative to the UTC in the database/temp-table field or the variable. This occurs so it can be indexed in absolute terms. When displaying the value, the AVM converts the value to the local time relative to the time zone.

Date and time operators and functions

ABL provides operators and built-in functions for working with dates and times.

Date and time operators and functions
+ Date addition operator
- Date subtraction operator
+ Datetime addition operator
- Datetime subtraction operator
ADD-INTERVAL function
DATE function
DATETIME function
DATETIME-TZ function
DAY function
ETIME function
INTERVAL function
ISO-DATE function
MONTH function
MTIME function
NOW function
TIME function
TIMEZONE function
TODAY function
WEEKDAY function
YEAR function

The following example code uses several of these operators and functions:

SESSION:DATE-FORMAT = "mdy".
MESSAGE "Today's date is" TODAY SKIP
  "Today's datetime is" NOW SKIP
  "Tomorrow's date is" TODAY + 1 SKIP
  "Yesterday's date was" TODAY - 1 SKIP
  "The current month is" MONTH(TODAY) SKIP
  "Last month was" MONTH(TODAY) - 1 SKIP
  "Next year is" YEAR(TODAY) + 1 SKIP
  "The current datetime is" NOW SKIP
  "The current datetime in ISO-Date format is" ISO-DATE(NOW)
  VIEW-AS ALERT-BOX.

Running the example code produces output similar to the following:

Today's date is 03/25/20 
Today's datetime is 03/25/2020 16:56:10.826+00:00 
Tomorrow's date is 03/26/20 
Yesterday's date was 03/24/20 
The current month is 3 
Last month was 2 
Next year is 2021 
The current datetime is 03/25/2020 16:56:10.826+00:00 
The current datetime in ISO-Date format is 2020-03-25T16:56:10.826+00:00

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.

DEFINE VARIABLE formattedDate AS CHARACTER NO-UNDO.

formattedDate = STRING(DAY(TODAY), "99") + "/" +
                STRING(MONTH(TODAY), "99") + "/" +
                STRING(YEAR(TODAY), "9999").

MESSAGE formattedDate VIEW-AS ALERT-BOX.

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.

MESSAGE "Today's date is" TODAY SKIP 
  "Today's date and time is" NOW 
  VIEW-AS ALERT-BOX.

SESSION:DATE-FORMAT = "dmy".

MESSAGE "Date format changed." SKIP 
  "Today's date is" TODAY SKIP
  "Today's date and time is" NOW 
  VIEW-AS ALERT-BOX.
Running the code produces the following output:
Today's date is 04/25/20 
Today's date and time is 04/25/2020 14:54:31.648-04:00
Date format changed. 
Today's date is 25/04/20 
Today's date and time is 25/04/2020 14:54:31.649-04:00

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.

The syntax for the INTERVAL function is shown:
INTERVAL(dtVal1, dtVal2, interval-type)
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.

VAR DATE dtShipDate = 02-14-2020.
VAR DATETIME-TZ dtOrderTime = "02-01-2020 10:15-5:00".

MESSAGE "Order time:" dtOrderTime SKIP
  "Ship date:" dtShipDate SKIP
  "Days to process order:" INTERVAL(dtShipDate,dtOrderTime,"days")
  VIEW-AS ALERT-BOX.

Running the code produces the following output:

Order time is: 02/01/2020 10:15:00.000-05:00 
Ship date is: 02/14/20 
Days to process order: 12