Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SQLite中按月份和年份进行选择_Sqlite_Winrt Xaml_Sqlite Net - Fatal编程技术网

如何在SQLite中按月份和年份进行选择

如何在SQLite中按月份和年份进行选择,sqlite,winrt-xaml,sqlite-net,Sqlite,Winrt Xaml,Sqlite Net,在我的SQlite表中,它有DateTime字段示例:order\u date 如何执行这些任务: 按月份检索记录,如2013年的1月、2月、3月等。 按开始日期和结束日期检索记录,条件如下1 谢谢 How to convert `DateTime` for format requires by SQLite for (1) and (2) DateTime Dt = new DateTime.Today(); Month-year ? Year? Recor

在我的SQlite表中,它有DateTime字段示例:order\u date

如何执行这些任务:

按月份检索记录,如2013年的1月、2月、3月等。 按开始日期和结束日期检索记录,条件如下1 谢谢

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? 我想你正在使用

因此,您可以在查询中使用参数:

//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));

order_date列中的值的格式是什么?此order_date在插入记录时采用DateTime中的值。您的解决方案显示格式为yyyy-mm-dd的日期范围。我想按yyyy-mm进行筛选,即2013年2月或2013年2月?2013年2月由2013-02-01到2013-03-01的所有日期组成,但不包括2013-03-01。。。这是怎么回事???如果您确定DateTime在数据库中以yyyy-mm-dd hh:mm:ss的形式写入,您可以使用“2013-02-%”之类的匹配,但我的答案与处理DateTime一样更安全。我的意思是允许用户过滤记录。示例:2012年2月和2013年2月,这样可以避免仅在2月之前进行筛选。日期时间基于.Net,我直接插入它。订单\日期=日期时间。今天。这是问题吗?不,这不是问题。你看。您只需要始终使用DateTime来确保始终以相同的方式处理它。我允许用户过滤记录-对,但用户在应用程序中过滤,而不是直接在数据库中过滤!!!您的应用程序必须做任何事情,不仅仅是连接到数据库!!!