web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Ax 2012 What can I use instead of Global::TimeDifference method?

(0) ShareShare
ReportReport
Posted on by

 Global::TimeDifference method was used in ax 2009. I want to replace a same method in 2012.

What can I use to get the difference between two dates in dynamics ax 2012  just convert the dates into numbers and subtract one from the other. The result type would be TimeHour24.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at

    The calculation you described can return values outside TimeHour24 data type? How do you want to handle these cases?

    Maybe you're looking for timeConsumed().

    Also consider using DateTimeUtil::getDifference() and calculating what exactly you need. Using .NET functions for subtracting DateTime values (and returning TimeSpan) are also very useful in some cases.

  • Verified answer
    5400 Profile Picture
    7,162 on at

    Hi Inci,

    can you cehck with below code.

    static void TimeDiff_JOB(Args _args)

    {    

       FromTime            fromTime;

       ToTime                toTime;    

       FromDateTime    ftime;    

       ToDateTime        ttime;

       fromTime    = timeNow();    

       toTime      = timeNow() + 300;     //Timeconsumed()

       info(strFmt('Time consumed %1', timeConsumed(fromTime, toTime)));

       ftime      = DateTimeUtil::newDateTime(systemDateGet(),timeNow());

       ttime      = DateTimeUtil::newDateTime(systemDateGet(),timeNow() + 300);            

        //DateTimeUtil::getDifference

       info(strFmt('Get difference %1', time2StrHMS(int642int(DateTimeUtil::getDifference(ttime, ftime)))));

    }    

    Thanks

    Bhaskar

  • 5400 Profile Picture
    7,162 on at

    I did it for one of my client.

  • Community Member Profile Picture
    on at

    Firstly, thanks everyone for answers.

    I write a method as below code.

    static TimeHour24 GetTimeDifference(TimeHour24 _startTime, TimeHour24 _endTime)
    {
    TimeHour24 Time;

    ;

    Time = _endTime - _startTime;

    if(Time > 0)
    Time = Time;
    else if(Time < 0)
    Time = Global::timeMax() + Time;
    else
    Time = 0;

    return Time;
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans