Date Data Type

Denotes a date ranging from January 1, 1753 to December 31, 9999.

The displayed text format of the date is determined by your Region and Language Format setting in Windows.

Undefined dates

An undefined or blank date is specified by 0D. The undefined date is considered to be before all other dates.

Normal dates and closing dates

All normal dates have a corresponding closing date. The closing date for a given date is defined as a period of time that follows a given normal date and precedes the next normal date.

Syntax

The syntax for defining DateTime format follows the ISO standard.

  • The syntax for defining Date format is yyyymmddD, where D is a mandatory letter. For example, 20180325D, read as the 25th of March, 2018.

To assign a normal date to a variable, use the following format: yyyymmddD.

Storing dates in the SQL server database

SQL Server stores information about both date and time in columns of the DATETIME types. For date fields, Dynamics 365 Business Central uses only the date and uses a constant value for the time. For a normal date, this constant value contains 00:00:00:000. For a closing date, it contains 23:59:59:000.

The Dynamics 365 Business Central undefined date is represented by the earliest valid date in SQL Server. The earliest valid date in SQL Server for a DATETIME is 01-01-1753 00:00:00:000.

If you store a date in the database that is outside the valid range for a SQL DATETIME, a run-time error occurs.

Example

This example shows a valid assignment of date. This example is compiled and run on a computer with the regional format set to English (United States).

var
    Date1: Date;
begin
    Date1 := 20180612D;  
    MESSAGE(FORMAT(Date1));  
end;

The message window displays the following:

06/12/2018

See Also

Getting Started with AL
Developing Extensions