Just Code‎ > ‎

RIA services - Crazy bug with DateTime dates, crazy solution

posted Mar 19, 2010, 5:25 AM by Peter Henell   [ updated Mar 22, 2010, 3:25 AM ]
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; } }
Comments