Share via


Dates

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

The date data type holds a complete date; that is, day, month, and year.

Scope and Precision

The date data type can hold dates in the closed interval [1\1\1900; 31\12\2154], that is: between January 1, 1900, and December 31, 2154.

Declaring Dates

Date declaration

=

date Variable { , Variable } ;

Variable

=

Identifier [ option ]

Option

=

arrayoptions | initialization

    //Simple declaration of a date variable, d
    date d; 
    //Multiple declaration of two date variables
    date d1, d2;
    //A date variable, d3, is initialized to the 21st of November 1998
    date d3 = 21\11\1998;
    //Declaration of a dynamic array of dates
    date d4[]; 

Date Literals

Dates can be written as literals in X++ by using the syntax:

Date literal = day \ month \ year

You must use four digits for the year.

Automatic Conversion

Dates are not automatically converted into other types, but you can use integer values in the computation of dates. For example:

void myMethod()
    {
        int anInteger;
        date aDate;
        ;
        // Sets the date variable adate to January 1, 1998
        aDate = 1\1\1998;
    
        // Sets the integer variable anInteger to 30.
        anInteger = 30;
    
        // Sets aDate to aDate + 30; that is the 31st of January 1998
        aDate = aDate + anInteger;
    }

Using Dates in Expressions

You can use dates in additions and subtractions when you are using the date as the principal type; that is, if you are subtracting from or adding to a date, like this:

date = date - integer or date = date + integer

You can also subtract two dates, and you can use dates in relational expressions.

Overview of Dates

Keyword

date

Size of data type

32 bits

Scope of data type

[1\1\1900; 31\12\2154]

Default value

The default is the minimum value of 1\1\1900. The minimum value is treated as null by X++ SQL statements.

Implicit conversions

None

Explicit conversions

str2date, date2str, date2num, int2date

See also

Data Types in X++

Variables

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.