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,
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
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.
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
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.
I need something to check on any format:
yyyymmdd, yy/mm/dd.
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
André Arnaud de Cal...
293,238
Super User 2025 Season 1
Martin Dráb
231,923
Most Valuable Professional
nmaenpaa
101,156
Moderator