Monday, June 25, 2018

User Date Sequence in D365 and Ax2012:

The below method will return the date sequence automatically.
Instead of hard coding as 123 or 213

str2Date(DateValue,123);

use the below code.


static int userDateSequence()
{
    int     ds1, ds2, ds3;
    date    d = str2Date('2015/12/18', 321);
    str     s = strFmt('%1', d);


    void datepart(str strDate, str dval, int part)
    {
        if (strEndsWith(strDate, dval))
            ds3 = part;
        else if (strStartsWith(strDate, dval))
            ds1 = part;
        else
            ds2 = part;
    }


    datepart(s, '18', 1);
    datepart(s, '12', 2);
    datepart(s, '2015', 3);

    return ds1 * 100 + ds2 * 10 + ds3;
}

No comments: