Notifications
Announcements
No record found.
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
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
I need something to check on any format:
yyyymmdd, yy/mm/dd.
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.
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
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 4 Most Valuable Professional
Priya_K 4
MyDynamicsNAV 2