c# - Why does strftime() not work in Sqlite when dates are stored as ticks? -


i have following code:

    [test]     public void sqlitetest()     {         var insertquery = @"insert metricdata (date) values (@date)";         var selectquery = @"select strftime('%y',date) 'year', date metricdata";          var connectionstring = "data source=:memory:;version=3;datetimeformat=ticks;";         using (var db = new sqliteconnection(connectionstring))         {             db.open();             databaseschemabuilder.initializeschema(db);              var testdate = datetime.now;             using (var cmd = new sqlitecommand(insertquery, db))             {                 cmd.parameters.addwithvalue("@date", testdate);                 cmd.executenonquery();             }              using (var cmd = new sqlitecommand(selectquery, db))             {                 using (var reader = cmd.executereader())                 {                     reader.read();                     var querieddate = reader.getdatetime(1);                     var year = reader.getstring(0);                      assert.areequal(testdate, querieddate);                     assert.areequal("2013", year);                 }             }         }     } 

when run code, first assertion passes second 1 fails, year equalling 1968 (other format values incorrect, month comes 19 example).

when looking @ raw query output, year result 1968 , date 635120225608999130.

why strftime() not working in instance?

edit: add, date column have defined date integer. also, if not include datetimeformat=ticks in connection string assertions pass.

date integer in sqlite uses unix time allows oldest date of 1970-01-01 00:00:00 utc. 1968 year value error , not pass assert.areequal("2013",year).

see documentation

and removing datetimeformat=ticks; in connection string means going use default iso8601 allow date prior 1970-01-01 , reason assert passes.

see reference


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -