Im facing the problem of storing a DateTime object in a datatable, it loses the type information set in it. For example, if DateTime.Kind is UTC, as soon as I set it to datarow, it will change to Unspecified. Please find the code below.
public class LocalTimeToUtcConverter { public DateTime Convert(DateTime localDate) { var utcOffset = TimeZoneInfo.Local.GetUtcOffset(localDate); var utc = localDate.ToUniversalTime(); return utc + utcOffset; } } [Test] public void Should_set_datetime_column_kind_to_utc() { var localDate = new DateTime(2010, 11, 01, 00, 00, 00); Assert.That(localDate.Kind == DateTimeKind.Unspecified); var converter = new LocalTimeToUtcConverter(); DateTime date = converter.Convert(localDate); Assert.That(localDate.Kind == DateTimeKind.Utc); var data = CreateTable(date);
Please tell me a workaround for this?
Thanks!!!
c # datetime datatable
Mike
source share