Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

Calculate difference between two dates?

(0) ShareShare
ReportReport
Posted on by 387

Dear Experts,

I have customized the new page, name is 'Purchase Line Details'. Here I have calculated the the PO approval date. it is working fine. Now, I want to make a difference between indent date and PO approval date....my code is giving the below error. Please help me to short it.

OnAfterGetRecord()

CLEAR(dtApproval);
ApprovalEntry.RESET;
ApprovalEntry.SETRANGE(ApprovalEntry."Document No.","Document No.");
IF ApprovalEntry.FINDLAST THEN BEGIN
AppID:=ApprovalEntry."Approver ID";
dtApproval:=ApprovalEntry."Approval Date-Time";
END;

dtApprove:=DT2DATE(dtApproval); //(conversion date time to date field)


dateDifference:=(dtApprove)-("Requisition Date");

when i try to run my customized page...it is showing the below error...

pastedimage1616567899804v1.png

  • navision begginers Profile Picture
    navision begginers 387 on at
    RE: Calculate difference between two dates?

    i have already tried...but still getting the same error messages. please help me to resolve it.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Calculate difference between two dates?

    Put an if condition like below

    if dtApprove <> 0D then begin 

    dtApprove:=DT2DATE(dtApproval); //(conversion date time to date field)


    dateDifference:=(dtApprove)-("Requisition Date");

    end;

  • navision begginers Profile Picture
    navision begginers 387 on at
    RE: Calculate difference between two dates?

    Yes, your are right. Most of the documents, dtApprove and 'Requisition Date' are blank in purchase line. what should i do sir. Please help me to resolve it.

    Thanks in advance for any help you're able to give with this.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Calculate difference between two dates?

    Please make sure you have the value in dtApproval and also in dtApprove before you calculate the difference.

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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans