RIA services - Crazy bug with DateTime dates, crazy solution

Post date: Mar 19, 2010 12:25:32 PM

Blog post about the bug http://smehrozalam.wordpress.com/2009/08/07/ria-services-how-dates-are-handled-and-sent-across-the-wire/

My quick and dirty solution, create a value converter and use it to display the date value. Only viable since my dates are read only in this case.

public class DateConverter : IValueConverter

{ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { DateTime date = (DateTime)value; return date.AddDays(1).ToString("yyyy-MM-dd"); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string strValue = value.ToString(); DateTime resultDateTime; if (DateTime.TryParse(strValue, out resultDateTime)) { return resultDateTime; } return value; } }