Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Difference between two DateTimeValues from History Table.

Posted on by 205

Dear All Experts,

Good Day

I have one History table where we maintain user and service order records when user create service Order

1st line generated with stage Id "Created" and when he change the stage to Next "In process" then 2nd line generated.

I need to make report their I need to show the difference between two DateTimeValue.

60282.Capture.PNG

As you saw in image two record generated for one service order with different stages. I need difference that DateTimeValue.

if (historyTable.StageId== 'Created' &&
historyTable.Progress == SMAServiceOrderProgress::InProcess)
{
	historyTmp.CreatedToInprocessDate = historyTable.createdDateTime;
}

if (historyTable.StageId== 'In Process' &&
historyTable.Progress == SMAServiceOrderProgress::InProcess)
{
	historyTmp.InProcessToTodayDate = historyTable.createdDateTime;
}

historyTmp.ProcessDiff = DateTimeUtil::getDifference(historyTmp.CreatedToInprocessDate , historyTmp.InProcessToTodayDate);


This is not working for me.

*This post is locked for comments

  • DEEPAKNONU Profile Picture
    DEEPAKNONU 205 on at
    RE: Difference between two DateTimeValues from History Table.

    Thanks, Khurshid these mutliple records because of multiple Team ID fields values which is not show in the image. I noticed now.

  • Suggested answer
    Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: Difference between two DateTimeValues from History Table.
    //Deepak you are inserting in the wrong sequence. 
    //that's why it creates multiple lines. Try to keep historyTmp inserting loop outside like this. 

    Select * from historyTable where historyTable.StageId== 'Created' && historyTable.Progress == SMAServiceOrderProgress::InProcess { Select firstonly from historyTable2 where historyTable2.StageId== 'In Process' && historyTable2.Progress == SMAServiceOrderProgress::InProcess && historyTable2.salesId == historyTable.salesId; if(historyTable2) { historyTmp= new historyTmp(); // new instance historyTmp.CreatedToInprocessDate =historyTable.createdDateTime historyTmp.InProcessToTodayDate = historyTable2.createdDateTime; historyTmp.ProcessDiff= DateTimeUtil::getDifference(historyTmp.CreatedToInprocessDate , historyTmp2.InProcessToTodayDate); historyTmp.insert(); } }
  • DEEPAKNONU Profile Picture
    DEEPAKNONU 205 on at
    RE: Difference between two DateTimeValues from History Table.

    2063.Capture1.PNGThanks Khurshid, code is working fine and value coming like this.

  • DEEPAKNONU Profile Picture
    DEEPAKNONU 205 on at
    RE: Difference between two DateTimeValues from History Table.

    Thanks, Nikolaos  difference means I need to show one field in my report which contain the days coming from historyTmp.CreatedToInprocessDate , historyTmp.InProcessToTodayDate means the difference .

    Suppose user created  service order 2 days before. and after 2 days he will process to next stage . So I need to show in how many days he process to next stage in my report.

     and field name is in report is "Created to In process".

    And their is no any error showing.

  • Khurshid Wali Profile Picture
    Khurshid Wali 922 on at
    RE: Difference between two DateTimeValues from History Table.

    Hi Deepak,

    Please add query loop and line where you insert historyTmp to your question. These details are not enough.

    I think your historyTmp buffer is different for CreatedToInprocessDate and inProcessToTodayDate.

    run debugger and check these two value at the time of Insertion.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Difference between two DateTimeValues from History Table.

    When you share your code, please use the "Use rich text formatting" -> "</>" to format your code. This time I did it for you.

    What do you mean by the difference? In what kind of format do you want to show it? DateTimeUtil::getDifference returns the difference in seconds. If you want to show something else than seconds, you need to process the result somehow.

    What do you mean by "This is not working for me"? Do you get some error? If yes, what is the error?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans