Saturday, March 16, 2019

How to get the User Date Sequence in Axapta2012 / D365OF:

Normally, we specify 123 or 321 sequence in str2Date(). But, in order to get the sequence randomly the below code is useful:

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: