2013-12-16 44 views
1

我正在尝试解决问题 我将数据保存在sqlite中。 日期格式为如何按当前时间在ios中对sqlite中的数据进行排序

NSDateFormatter *df= [[NSDateFormatter alloc]init]; 
df.dateStyle = NSDateFormatterMediumStyle; 
df.dateFormate = @"dd-MM-yyyy"; 
DateTextField.text = [NSString stringWithFormat:@"%@",[df stringFromDate:MyPicker.date]]; 

节省在SQLite表的值。

我在表currentdate,pastdate,futuredate中有三个按钮。

当我按下的currentdate按钮时,的currentdate值示于表中,

当我按下pastdate按钮时,pastdate值示于表中,

当我按下futuredate按钮时,futuredate值是在表中显示。

在pastdate是SQLite的查询类型的数据是

NSString *Querysql = [NSString stringWithFormate:@"SELECT *FROM Table_Name where Date > '16-12-2013' order by date DESC"]; 

如何在当前的日期显示?

什么是查询获取当前日期,sqlite表中的值?

+0

使用“DD-MM-YYYY”将你的代码过于复杂,并阻止你使用许多优化,例如' INDEX'es。使用“yyyy-MM-dd”按照需要在应用程序中显示数据库和格式的日期。检查[SQLite日期/时间](http://www.sqlite.org/lang_datefunc.html)。 –

回答

0

获取当前日期第一

NSDate *date = [NSDate date]; 

// format it 
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; 
[dateFormat setDateFormat:@"dd-MM-yyyy"]; 

// convert it to a string 
NSString *dateString = [dateFormat stringFromDate:date]; 

然后使用查询

String Querysql = "SELECT *FROM Table_Name where Date = \""+dateString+"\" "; 
相关问题