I have got an SQLite DB where I store a start and end value. These values are stored as a string (TEXT)
I retrieve this data using the function below:
public IEnumerable<CalendarEvent> GetEvents()
{
return Get<IEnumerable<CalendarEvent>>(db =>
db.Query<CalendarEvent>("SELECT Summary, strftime('%Y-%m-%d %H:%M:%S', Start) AS Start, " +
"STRFTIME('%Y-%m-%d %H:%M:%S', End) AS End, " +
"Description,GoogleEventId,Client_ID " +
"FROM CalendarEvent", CommandType.Text));
}
The result should be returned as a list of the model CalendarEvent. The models look like this;
public class CalendarEvent
{
public string Summary
{
get; set;
} = string.Empty;
public DateTime Start
{
get; set;
} = DateTime.MinValue;
public DateTime End
{
get; set;
} = DateTime.MinValue;
public string Description
{
get; set;
} = string.Empty;
public string GoogleEventID
{
get; set;
} = string.Empty;
public int Client_ID
{
get; set;
} = int.MinValue;
}
The problem is the values for Start and End always have the value of DateTime.MinValue.
I somehow need a conversion, because if I don't use the strftime
in the select and just use
SELECT Summary, Start, End, Description FROM CalendarEvent
A value of 14-11-2022 12:00 for example i开发者_开发知识库s throwing an invalid DateTime Exception because it tries to handle 14 as a month.
Does anybody have an idea what the best way to solve this is?
精彩评论