Message definition example value error: String was not recognized as a valid DateTime.

Hi, How can you provide a example value for a date in the message definition? I tried a date (with and without "quotes”). I tried the currentdatetime token. But still receive this error, although I'm sure this is a valid date time, since it is accepted value in the request.   Regards, 
2 answers

Hi Jitze,

as stated here, Mendix only accepts

  • year-month-day
  • year-month-day hour:minute:second

as example values.


Parsing a string representation of a c# DateTime is a tricky thing because different cultures have different date formats. .Net is aware of these date formats and pulls them from your current culture (System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat) when you call DateTime.Parse(this.Text); You can either call DateTime.ParseExact and pass in the exact format string that you're expecting, or you can pass in an appropriate culture to DateTime.Parse to parse the date.


For example, this will parse your date correctly:


DateTime.Parse( "22/11/2009", CultureInfo.CreateSpecificCulture("fr-FR") );


Of course, you shouldn't just randomly pick France, but something appropriate to your needs.


What you need to figure out is what System.Threading.Thread.CurrentThread.CurrentCulture is set to, and if/why it differs from what you expect. The IFormatProvider parameter specifies the culture to use to parse the date. Unless your string comes from the user, you should pass CultureInfo.InvariantCulture. If the string does come from the user, you should pass CultureInfo.CurrentCulture, which will use the settings that the user specified in Regional Options in Control Panel.