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 :
Microsoft Dynamics AX (Archived)

date format issue

(0) ShareShare
ReportReport
Posted on by 451

Hi guys,

 

I am using a method to get the date .i want it ddmmyyyy format .Below is the code I am using :

public TransDate parmAccountingDate(TransDate _accountingDate = accountingDate)

{    

str s;        

s= date2str(_accountingDate,123,DateDay::Digits2,             DateSeparator::Slash,             DateMonth::Digits2,             DateSeparator::Slash,             DateYear::Digits4);   

 accountingDate = str2Date(s,123);                

    return accountingDate;

}

In this string s is having it in ddmmyyyy format but when I use str2Date the format changes to mmddyyyy.

Please help

 

Regards

Aman

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    str2date() returns a date, not a string. As dates are not strings, they don't have any string formats. They're basically just some format-agnostic numbers.

    AX converts them to string when displaying to users (such as in forms), taking users' regional settings into account, therefore different users can see the same date in different formats.

  • Deepak Agarwal Profile Picture
    8,602 on at

    Hi Aman,

    The date that you get from this conversion is coming form your system setting, you must be have mmddyyyy format thats why its coming like this only. Try to change your system format.

  • Dev Profile Picture
    451 on at

    Hi

    Thanks for your reply.

    Is there any way in which we can convert a date to ddmmyyyy irrespective of the regional settings through code ??

    regards

    Aman

  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Sure - when you convert it to string, you can define which format should be used. You already do that above with date2str().

    Again - "date" isn't string, therefore it has no format. If you want a specific string representation, convert the date to a string.

    In general, you should always work with dates (exactly because you avoid all problem regarding formats) and leave AX to format them for users. Convert dates to string only when necessary, e.g. when you're generating a text file where dates must follow a given format.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans