Reputation:
I create a programm with a sqllite DB where i can save Data (id/date/name).
DB:
1 - 15.09.2016 00:00:00 - Test
2 - 28.06.2018 00:00:00 - Test2
Type: Numeric
I try to read this out with a SQLite Reader.
Code:
String sql = $"SELECT * FROM test";
SQLiteCommand command = new SQLiteCommand(sql, dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine($"Date: {reader["date"]}");
...
}
Output:
15,09
28,06
If i convert this to Datetime i get only the year 2018:
15.09.2018
28.06.2018
How can i read out the Datetime in correct format with year ?
Upvotes: 0
Views: 1772
Reputation: 2734
https://www.sqlite.org/datatype3.html
SQLite don't have DateTime Datatype. You should parse the string ISO8601.
DateTime myDateTime = DateTime.ParseExact(myString, myFormat, CultureInfo.InvariantCulture);
SqliteDataReader got a GetDateTime
method.
reader.GetDateTime(1).ToString("dd.MM.yyyy")
Upvotes: 1