SQLite日期"大于其他日期"例如' 25/09/2014'不起作用

时间:2014-09-29 21:00:44

标签: sqlite date

我的SQLite存在问题,特别是我的约会。 如果我执行以下查询:

SELECT g.Date FROM game w where g.date = "26/09/2014" order by timestamp desc

会给我

  • 26/09/2014
  • 26/09/2014
  • 26/09/2014

但是当我将查询项 = 更改为 &gt; 并将日期更改为 < EM> “25/09/2014”

SELECT distinct g.Date FROM gamew where g.date > "25/09/2014" order by timestamp desc

会给我以下结果(我添加了 - distinct)

  • 26/09/2014
  • 31/08/2014
  • 30/08/2014
  • 29/08/2014
  • 28/08/2014
  • 27/08/2014
  • 26/08/2014
  • 31/07/2014
  • ...

这不是预期的结果:(因为,只有一天是正确的。 也 我真的不喜欢更改数据库,Date项。我更喜欢有正确的查询给我正确的基准回复

示例数据库

ID - Country - League - Team - Opponent - Location - Result - Scored - Against - Time - Date
--------------------------------------------------------------------------------
"20868","Spa","PRD","Celta_de_Vigo","Elche","A","1","1","0","1411758000","26/09/2014"
"47133","Ger","BUN","Hoffenheim","Mainz_05","A","x","0","0","1411756200","26/09/2014"
"59149","Ger","BUN","Mainz_05","Hoffenheim","H","x","0","0","1411756200","26/09/2014"
"25373","Spa","PRD","Cordoba","Valencia"   ,"A","0","0","3","1411675200","25/09/2014" 
 ... 11655 rows ...

修改 g.Date的类型:

DATE       DATE 

1 个答案:

答案 0 :(得分:4)

DD / MM / YYYY不是有效的SQLite日期。

SQLite没有实际的日期类型,并允许您将它们存储为TEXT,INT或REAL。如果您选择TEXT,必须使用YYYY-MM-DD格式,该格式可以被SQLite的日期函数识别,并且无论如何都将解决您的排序和搜索问题。