Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Check whether a date is valid

(0) ShareShare
ReportReport
Posted on by

Hello,

In AX 2009 - How can I check whether a date string is a valid date (on any format) ?

Thanks :)

*This post is locked for comments

  • David Massey Profile Picture
    on at
    Re: Check whether a date is valid

    Let me ask the obvious question.  Why are you using a string control?  If your users interface is bound to a date control, you don't have the conversion problem.

  • Amir Nazim Profile Picture
    5,994 on at
    Re: Check whether a date is valid

    Below is the method using .net classes, you can use similar method in AX. You can also use the .net classes in dynamics ax to build same method.

    public bool validate_datet(stirng date, string date_format)
    {
    try
    {
    DateTime.ParseExact(date, date_format, DateTimeFormatInfo.InvariantInfo);
    }
    catch
    {
    return false;
    }
    return true;
    }

    let me know if you needed any more help

  • Suggested answer
    Nasheet Siddiqui Profile Picture
    440 on at
    Re: Check whether a date is valid

    One of the ways to do it to use validate it using regular expression.

    Here you can find how can you use regular expression in x++ to validate characters.

    validate special character using regular expression in ax

    you just have t o replace regulare expression of the date pattern you wish to validate.

     

  • Community Member Profile Picture
    on at
    Re: Check whether a date is valid

    I need something to check on any format:

    yyyymmdd, yy/mm/dd.

  • Suggested answer
    Matthew Feist [MSFT] Profile Picture
    75 on at
    Re: Check whether a date is valid

    Hello Eitan!

    In AX 2009, you can use the str2date() function to accomplish this.

    It takes two parameters, the first being your date in string format, and the second being the numerical sequence representing the sequence ordering of the date's components (day, month, year).

    In order to use this function, you'll need to know before hand what the sequence order is, but it appears to handle string dates having common delimiters. If it can't parse the string, it'll return a zero date, which you can check for.

    If you have a date string that changes in terms of the order sequence of day, month and year, you'll need to do some string parsing before calling this.

    Here's a link to the MSDN article for more information:

    http://msdn.microsoft.com/en-us/library/aa554244(v=ax.10).aspx

    Thanks!
    Matt

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,238 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans