Skip to main content

Notifications

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

Date Issue while entering it through AL Code

Posted on by 95
Hello,
I'm experiencing an issue with my extension that creates new purchase invoices by reading from an Excel sheet. The date that gets uploaded to Business Central is always one day less than the exact date in the Excel sheet.
For example, if the date in the Excel sheet is 3/14/2024, it gets stored as 3/13/2024 in Business Central.
Here's the code I'm using to upload the date:
Evaluate(PurchHeaderRec."Posting Date", DelChr(GetText(Buffer, RowNo, 6), '<'));//mmddyyyy
        
I've tried debugging the code by extracting the date components using Date2DMY and reassembling the date using DMY2Date, but the issue persists:
Evaluate(PostingDate, DelChr(GetText(Buffer, RowNo, 6), '<'));
Month := Date2DMY(PostingDate, 1);
Day := Date2DMY(PostingDate, 2);
Year := Date2DMY(PostingDate, 3);
PurchHeaderRec."Posting Date" := DMY2Date(Day, Month, Year);
        
Has anyone else experienced this issue, and if so, how did you resolve it? I'd appreciate any help or guidance on this matter.
 
 
  • BBC_dhanvi Profile Picture
    BBC_dhanvi 95 on at
    Date Issue while entering it through AL Code
    I tried using the timezone offset but it now reduces one more day.
     
    Code used is as follows :
     local procedure GetDateTimeZoneAdj(var Buffer: Record "Excel Buffer" temporary; Row: Integer; Col: Integer): Date
        var
            dt: DateTime;
            TimezoneOffset: Duration;
            TypeHelper: Codeunit "Type Helper";
        begin
            if Buffer.Get(Row, col) then begin
                Evaluate(dt, Buffer."Cell Value as Text");
                TypeHelper.GetUserClientTypeOffset(TimezoneOffset);
                dt := dt + TimezoneOffset;
                exit(DT2DATE(dt));
            end;
        end;
     
     
     
    This is only happening during reading from excel. if i do a csv import is reads fine.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 71,688 Super User 2024 Season 2 on at
    Date Issue while entering it through AL Code
    This is a bit strange, I tested it before and it didn't have this problem.
    But it seems that the system uses the UTC date by default in your environment, so one day is reduced.
    You can recalculate the date using the timezone offset to see if this problem still exists.
    Dynamics 365 Business Central: How to get timezone offset in AL
     
    Hope this can give you some hints.
    Thanks
    ZHU
     
  • gdrenteria Profile Picture
    gdrenteria 11,065 Most Valuable Professional on at

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,302 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans