在我的SQlite表中,它有DateTime字段示例:order_date
如何执行这些任务:
由于
How to convert `DateTime` for format requires by SQLite for (1) and (2) DateTime Dt = new DateTime.Today(); Month-year ? Year? Records = await db.QueryAsync("Select * From Purchase where order_date=" + "Month-Year"); In SQLite , which operator is correct : `=` or `==`? ----- Update: using SQlite:strftime SELECT * FROM tablename WHERE strftime('%Y', Order_Date) = '2013' AND strftime('%m', Order_Date) = '2'; 1) Is there a function to get month as number from DateTime?
答案 0 :(得分:1)
我假设您使用的是sqlite-net。
因此,您可以在查询中使用参数:
//Returning all records from February 2013
Records = await db.QueryAsync<Purchase>("Select * From Purchase where order_date >= ? and order_date < ?", new DateTime(2013, 2, 1), new DateTime(2013, 3, 1));