timeConsumed()–a very useful function in Global class in AX 2012 [x++]


There is a very useful function timeConsumed() in Global class which we can use to calculate the time taken to execute business logic in AX 2012.

This function will return time consumed string in the form of X hours X minutes X seconds. If X is 0 – will not include the value + text.
It handles up to a 24 hour time difference not dependent on start/end time. If time consumed > 24 hours will only report time over 24 hour intervals.

Below is the example:

static void SGX_timeConsumed(Args _args)


    FromTime startTime = timeNow();

    int i;

    str dummyStr;



    for (i = 1 ; i <= 500000; i++)


        dummyStr += int2str(i);     



    info(strFmt("Total time consumed is  %1", timeConsumed(startTime, timeNow())));



time consumed 

Happy Dax6ng,

Sreenath Reddy G


One Response to “timeConsumed()–a very useful function in Global class in AX 2012 [x++]”

  1. Alex Says:

    Neat. I used this to convert seconds to a “speakable” output by having the start time be 0. So 1900 seconds, outputs “31 minutes 40 seconds” with info(timeConsumed(0,1900));

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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


Connecting to %s

%d bloggers like this: