Hey Robert,
I have a simple request: could you change the SQLiteConvert.ToDateTime(string) from this:
switch (_datetimeFormat)
{
case SQLiteDateFormats.Ticks:
return new DateTime(Convert.ToInt64(dateText, CultureInfo.InvariantCulture));
case SQLiteDateFormats.JulianDay:
return ToDateTime(Convert.ToDouble(dateText, CultureInfo.InvariantCulture));
default:
return DateTime.ParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None);
}
to something like this:
switch (_datetimeFormat)
{
case SQLiteDateFormats.Ticks:
return new DateTime(Convert.ToInt64(dateText, CultureInfo.InvariantCulture));
case SQLiteDateFormats.JulianDay:
return ToDateTime(Convert.ToDouble(dateText, CultureInfo.InvariantCulture));
default:
{
DateTime convertedDate = DateTime.MinValue;
DateTime.TryParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out convertedDate);
return convertedDate;
}
}
I ended up making this change for a project I am working on that uses data ported from MySQL. The client is using the empty date (0000-00-00 00:00:00) instead of NULL. The empty date was causing ParseExact to fail with FormatException (not a valid datetime); TryParseExact is a nice replacement because it will return DateTime.MinValue if the conversion fails.