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 :
Small and medium business | Business Central, N...
Suggested Answer

Date Issue while entering it through AL Code

(1) ShareShare
ReportReport
Posted on by 160
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.
 
 
I have the same question (0)
  • Gerardo Rentería García Profile Picture
    25,390 Most Valuable Professional on at
  • Suggested answer
    YUN ZHU Profile Picture
    95,763 Super User 2025 Season 2 on at
    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
     
  • BBC_Astha Profile Picture
    160 on at
    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.

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,116

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 764 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 635 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans