2012-03-01 158 views
1

在我的SQLite數據庫有一個「日期」字段,&它的數據類型爲varchar,如何從sqlite數據庫獲取兩個日期之間的所有數據?

我想兩個日期之間獲得的所有數據 - 我會怎麼做這從一個SQLite數據庫?

+0

http://stackoverflow.com/a/1976040/919545 – 2012-03-01 10:24:31

+0

顯示任何記錄的日期。你在記錄中使用哪個日期犯人? – 2012-03-01 10:41:18

+0

[SQLite DateTime comparison]的可能重複(http://stackoverflow.com/questions/1975737/sqlite-datetime-comparison) – Mark 2012-03-01 12:06:10

回答

2

試試這個

NSString * sql = [[NSString alloc] initWithFormat:@"SELECT * FROM table WHERE (startdate <='%@') AND (enddate >='%@)",startdateString, enddateString]; 

OR

SELECT * FROM table WHERE datecol BETWEEN '2012-02-08 00:00:00' AND '2012-01-10 00:00:00' 
0
  1. 日期(TIMESTRING,改性劑,改性劑,...)
  2. 時間(TIMESTRING,改性劑,改性劑,...)
  3. 日期時間(TIMESTRING,改性劑,改性劑,...)
  4. 儒略日(TIMESTRING,改性劑,改性劑,...)
  5. 的strftime(格式,TIMESTRING,改性劑,改性劑,...)

使用上述功能之一,您的字符串轉換爲日期 更多詳細信息請參考:http://www.sqlite.org/lang_datefunc.html

+0

將它轉換爲日期之後,試試這個:SELECT data FROM myTable WHERE date BETWEEN date1 AND date2 – 2012-03-01 10:28:51

相關問題