Skip to main content

Notifications

Announcements

No record found.

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

Evaluating date string of any date format into current system's date format in D365 Business Central

Posted on by 241

Hi,


Hope you all are doing well. In Business Central, I'm receiving dates from third party application. Date's format is based upon the region/language or user. For example d/M/yyyy, d-M-yyyy, M/d/yyyy, M-d-yyyy, d.M.yyyy, M.d.yyyy etc.


After receiving date in text from 3rd part app when I try to evaluate it into type Date Business Central throws an error that '28.1.2021.' can not be evaluated into type Date, '28-1-2021' can not be evaluated into type Date etc. Let's say date I received is '28/1/2021'. System gives an error gives an error that  '28/1/2021' can not be evaluated into type Date

pastedimage1659253705710v1.png


Actually, I guess, system is accepting only 1 specific format that is selected in page 'My Stettings'

pastedimage1659253720301v2.png


In page My Settings if date format is d/M/yyyy and the format I'm receiving from 3rd party app is also the same then this code doesn't throw any error.

pastedimage1659253741683v3.png


If in My Settings Page date format is M/d/yyyy, d.M.yyyy etc and the format I'm receiving from 3rd party app is d-M-yyyy or any other than the format selected on My Settings page, then this AL Code doesn't work.


Is there any way to get current system's date format and evaluating the received date string (having any format) into date type?


Answers will be highly appreciated. Thanks for reading.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: Evaluating date string of any date format into current system's date format in D365 Business Central

    Hi,

    You can try below code to create your Date from the string you are receiving.

    docs.microsoft.com/.../system-dmy2date-method

    var

       Day: Integer;

       Month: Integer;

       Year: Integer;

       OutputDate: Date;

       Text000: Label "Day number %1, month number %2, and year number %3 corresponds to the date %4.";  

    begin  

       Day := 17;  

       Month := 2;  

       Year := 2014;  

       OutputDate := DMY2Date(Day, Month, Year);  

       Message(Text000, Day, Month, Year, OutputDate);  

    end;

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,698 Super User 2024 Season 2 on at
    RE: Evaluating date string of any date format into current system's date format in D365 Business Central

    Hi, I think you can split it first and then recreate the date in BC using the method below.

    Text.Split(List of [Text]) Method

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/text/text-split-list%5Btext%5D-method

    https://yzhums.com/9273/

    System.DMY2Date(Integer [, Integer] [, Integer]) Method

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-dmy2date-method

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Jeffrey Bulanadi Profile Picture
    Jeffrey Bulanadi 644 on at
    RE: Evaluating date string of any date format into current system's date format in D365 Business Central

    Hi Javed,

    You can setup a data exchange definition and transformation rules that might help.

    docs.microsoft.com/.../across-how-to-set-up-data-exchange-definitions

    community.dynamics.com/.../using-data-exchange-definitions-and-transformation-rules-to-change-date-formats

    If you find this useful please give it a like or verify the answer. By this way you can help other members know that the topic has been answered. Have a nice day. Thank you.

    Cheers,

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: Evaluating date string of any date format into current system's date format in D365 Business Central

    Maybe you can try to add ,9 after your evaluate statement. If the date you receive is in xml format.

    That is the first thing i would try.

    docs.microsoft.com/.../evaluate-function

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans