Skip to main content

Notifications

Announcements

No record found.

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 73,696 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 12,183 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

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