str2Datetime Function

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

Generates a utcdatetime value from the specified string of date and time information.

utcdatetime str2datetime( str text, int sequence )





The string to convert into a utcdatetime value.


A three digit number that describes the sequence of the date components in the text parameter.

Return Value

A utcdatetime value that represents the specified date and time.


The syntax requirements for the date portion of the text parameter are flexible. The variety of valid formats is the same as in the date2str function.

Each of the following calls to str2datetime is valid and produce the same output:

utc3 = str2datetime( "1985/02/25 23:04:59" ,321 );
utc3 = str2datetime( "Feb-1985-25 11:04:59 pm" ,231 );
utc3 = str2datetime( "2 25 1985 11:04:59 pm" ,123 );

Each component of the date time is represented by a digit in the sequence parameter:

  • 1 – day

  • 2 – month

  • 3 – year

For example, YMD is 321. All valid values contain each of these three digits exactly one time. If the value of the sequence parameter is invalid, the regional settings are used to interpret the input text parameter.

If the input parameters describe an invalid date and time, an empty string is returned.


    static void JobTestStr2datetime( Args _args )
        utcdatetime utc3;
        str sTemp;
        utc3 = str2datetime( "1985/02/25 23:04:59" ,321 );
        sTemp = datetime2str( utc3 );
        print( "sTemp == " + sTemp );

See also

datetime2Str Function

Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).