AX – D365FO – convert datatime to string in a specific format

Custom formatting string in .NET makes it really easy.

static void Job61(Args _args)
{
    System.DateTime dateTime = System.DateTime::get_UtcNow();
    str utcTimeAsStr = dateTime.ToString('yyyyMdd_HHmmss');
    
    info(strFmt("Datetime in GMT: %1",utcTimeAsStr));    

}

This code achieves this output

Datetime in GMT: 20211105_113052

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s