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)

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

I have the same question (0)
  • Suggested answer
    Matthew Feist [MSFT] Profile Picture
    75 on at

    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

  • Community Member Profile Picture
    on at

    I need something to check on any format:

    yyyymmdd, yy/mm/dd.

  • Suggested answer
    Nasheet Siddiqui Profile Picture
    440 on at

    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.

     

  • Amir Nazim Profile Picture
    5,994 on at

    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

  • David Massey Profile Picture
    on at

    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.

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