我在sqlite表中以ISO8601格式示例2015-04-15T10:54:14Z存储日期,我想从表中获取最年期的日期。下面是我的sqlite表中的日期
2015-04-15T10:54:14Z
2015-04-15T10:54:115Z
2015-04-15T10:54:216Z
2015-04-15T10:54:320Z
2015-04-15T10:54:422Z
我正在尝试以下查询:
SELECT * FROM Table1 ORDER BY datetime("date_column") DESC ;
但我没有得到合适的结果。
答案 0 :(得分:2)
标准化为UTC的ISO 8601日期时间戳具有良好的属性,即字母(词典)顺序也是时间顺序。
您不需要datetime()
,您可以ORDER BY date_column DESC
先对它们进行最新排序,然后添加LIMIT 1
以获取最新版本。
答案 1 :(得分:0)
将您的查询更新为:
SELECT * FROM Table1 ORDER BY date_column DESC LIMIT 1
答案 2 :(得分:0)
使用此方法将日期列放入db:
public String getDatetime(){
//get time and date
Calendar c=Calendar.getInstance();
CharSequence s = DateFormat.format("yyyy-MM-dd HH:mm:ss", c.getTime());
//convert it to string array
return s.toString();
}
然后使用您之前使用的查询,因为datetime()接受特定的格式。