在Sqlite数据库中对日期进行排序 [英] Sort the date in Sqlite database

查看:616
本文介绍了在Sqlite数据库中对日期进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个iPhone应用程序,我将日期和时间存储在一列中,现在我想按照先发生的顺序对日期和时间进行排序。

I am making an iPhone application in which I am storing date and time in a column now I want to sort the date and time in the order which occurs first.

我怎么能这样做?请给我一些解决方案。

How can I do this? please give me some solutions.

推荐答案

NSDate 保存为 NSTimeInterval

NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970];

NSTimeInterval 只是 double 可以保存在SQLite数据库中。

The NSTimeInterval is just a double which you can save in the a SQLite database.

使用简单的SQL查询,然后可以选择排序:

With an simple SQL query you can then select the sort then:

SELECT * FROM dateTable ORDER BY myDateColumn DESC

并且只需返回 NSDate

NSDate *date = [NSDate dateWithTimeIntervalSince1970:databaseTimeInterval];

这篇关于在Sqlite数据库中对日期进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆