web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Answered

date reading behaviour

(0) ShareShare
ReportReport
Posted on by 619
Hi everyone, I'm working on a project where I'm capturing a GS1-style string, in which one of the substrings corresponds to the date. In my case, when converting it to a date format using the str2date method, I've noticed something strange:

 

If the string is in the format “991231”, the method returns it as 31/12/1999.

If it is “421231”, it returns 31/12/1942.

If it is “411231”, it returns 31/12/2041.

I would like to know why this is happening and if there is any way to make the string “991231” be interpreted as 12/31/2099, since I use that date for items that do not have an expiration date as such.

Thanks!

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    It's the expected behaviour. The system must somehow decides whether 99 means 1999 or 2099, and because 1999 is much more likely, it's used instead of 2099. Technically, there is a system parameter that controls from which year it's considered as a year in 21th century.
     
    You can either use your current way of parsing and then modify the result according to your needs, or change the way how the parsing logic determines the century. For example:
    System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("en-US");
    var calendar = cultureInfo.Calendar;
    calendar.TwoDigitYearMax = 2099;
    
    utcDateTime result = System.DateTime::ParseExact("991231", "yyMMdd", cultureInfo);
     
  • Jesús García Profile Picture
    619 on at
    Thanks Martin!

    I’d like to take this opportunity to point out that I’m having trouble reading this date-related string. In addition to what I mentioned earlier, we have another development project from an ISV where, after capturing a GS1 string, one of the values detected was the expiration date. The format for entering it was, as I mentioned before: “yymmdd”. Due to the situation I mentioned earlier in the post, and in search of a “solution,” I changed some date-related parameters on the VM, and now when I run the string, before it reaches the str2date section, the string has already been converted to the “yyyy/mm/dd” format, and when it reaches the method, it throws an error stating that it cannot be converted to date format. I’ve tried to fix it, but I’m still having the same problem. How should the VM’s format and date settings be configured? Thanks!

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    I think you're looking at the problem from a wrong perspective. There is no valid reason why a solution parsing a fixed format (991231) should depend on a particular configuration of the machine where it runs, and fail if the configuration is different. This dependency should be removed, instead of reconfiguring the VM and hoping that all other environments will always be configured accordingly. Don't forget that you don't even control configuration of production servers.
  • Jesús García Profile Picture
    619 on at
    Thanks Martin! I've found that my user config was wrong (something that i modified too.). Thanks for all our info. Have a good day!!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Mallesh Deshapaga Profile Picture

Mallesh Deshapaga 296

#2
Laurens vd Tang Profile Picture

Laurens vd Tang 234 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 139 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans