Inserting a DateTimeOffset value truncates sub-seconds #249

ploeh opened this Issue Dec 3, 2012 · 2 comments

2 participants


When inserting a record with the datetimeoffset column type, using a DateTimeOffset .NET structure seems to truncate the milliseconds of the inserted value.

As an example, I have a table defined in SQL Server 2012 Express like this:

CREATE TABLE [dbo].[JournalEntry](
    [UserId] [int] NOT NULL REFERENCES [dbo].[User](UserId),
    [Time] [datetimeoffset](4) NOT NULL,
    [Distance] [int] NOT NULL,
    [Duration] [time] NOT NULL

I'm inserting data into it like this:

dynamic entry = new ExpandoObject();
entry.time = DateTimeOffset.Now;
entry.distance = 6000;
entry.duration = TimeSpan.FromMinutes(31);
entry.UserId = userId; // The userId value comes from another query

As an example, when running while I'm writing this, according to my debugger, the time value is "2012-12-03T19:28:59.8001074+01:00".

However, after insertion into the database, the value, according to a SQL SELECT statement is "2012-12-03 19:28:59.0000 +01:00". Notice that the sub-second part of the value has been truncated.

As far as I can tell, this happens because Simple.Data.Ado.TypeHelper doesn't include DateTimeOffset in its BaseTypes set.

@markrendle markrendle added a commit that referenced this issue Dec 3, 2012
@markrendle Fix for issue #249 4ef5f4b

The fix solves my issue. Thank you for the fast response.

I don't know what your protocol is for issues in this project, but for my sake the issue can be closed now :)

@markrendle markrendle closed this Dec 3, 2012

Protocol!? Like I'm that organised. I fix it, you say it worked, I close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment