Sqlite-net datetime retrieval
Asked Answered
G

2

7

Hi I have a problem with retrieving datetime from SQLite database using sqlite-net library. Db column is of type DATE, example date in one of records is: 2013-08-02

I have a model:

internal class FCost
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    ...

    public DateTime AccountingDate { get; set; }

    ...
}

I execute this line of code:

var result = dc.Table<FCost>().ToArray();

Every field except AccountingDate is filled correctly, all DateTime fields are filled with value: {1/1/0001 12:00:00 AM} (visual studio debbuger view). Why is date not parsed correctly? I tried switching Db column type to DATETIME and TEXT but got same results.

EDIT. Object dc used above is of type SQLiteConnection from sqlite-net library.

Gotthard answered 2/8, 2013 at 12:33 Comment(1)
I have entered values to AccountingDate column manually via SQLite Expert Professional (there is a built-in datepicker)Gotthard
E
6

There is a StoreDateTimeAsTicks property on the SQLiteConnection object that you should use. Set it to 'false'. Worked for me.

Exuviate answered 22/8, 2015 at 5:30 Comment(1)
Should be accepted. Argument is sent on contructor and Date is filledUnknowable
S
0

Instead of DATETIME, USE Data type as Date to STORE DATE WITHOUT TIME.

Refer this.link http://www.tutorialspoint.com/sqlite/sqlite_data_types.htm

I hope it will help you.

Summit answered 2/8, 2013 at 14:36 Comment(1)
I indicated in my question that Db column (SQLite database side) is of type DATE. DateTime is .net type I use in my model. Also, I have tried storing date in database in a field of type DATETIME and TEXT, but as stated in my question, the results were the same.Gotthard

© 2022 - 2024 — McMap. All rights reserved.