Skip to content

Reading DateTime ticks from DB is converting it to int (and therefore getting the wrong value) #8

@yhorowitz

Description

@yhorowitz

I have the following query that insert a DateTime object into the table:

using (SQLiteConnection Connection = new SQLiteConnection(new SQLitePlatformGeneric(), "mydbpath"))
{
    Connection.Execute("INSERT INTO punch(user_id, punch_type, punch_time, punch_comment)  VALUES(@user_id, @punch_type, @punch_time, @punch_comment)", new object[] { 1, "in", DateTime.UtcNow, "" });
}

I then use the following code to read the date data:

using (SQLiteConnection Connection = new SQLiteConnection(new SQLitePlatformGeneric(), db.ConnectionString))
{
    SQLiteCommand cmd = Connection.CreateCommand("SELECT punch_time FROM punch WHERE user_id = @user_id", new object[] { 1 });
    var result = cmd.ExecuteDeferredQuery();
}

The data gets written into the database well with 'punch_time' being 636439764482923774.

However, when I get the data back it shows up with the incorrect value of 49290494. This is the value an int would have if it was casted from the long value of the expected date ticks value. It appears the the ExecutedDeferredQuery method is casting it into an int before returning it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions