1

In my sqlite database there is a "Date" field, & its data type is varchar,

I want to get all data between two dates - how would I do this from a sqlite database?

Stev_k
  • 2,118
  • 3
  • 22
  • 36
Anki
  • 589
  • 2
  • 13
  • 22

3 Answers3

2

Try this

 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'
Hector
  • 3,909
  • 2
  • 30
  • 46
0
  1. date(timestring, modifier, modifier, ...)
  2. time(timestring, modifier, modifier, ...)
  3. datetime(timestring, modifier, modifier, ...)
  4. julianday(timestring, modifier, modifier, ...)
  5. strftime(format, timestring, modifier, modifier, ...)

Use one of the above function to convert your string to date More detail please refer: http://www.sqlite.org/lang_datefunc.html

Hanon
  • 3,917
  • 2
  • 25
  • 29
0

The best solution is here: Working with strings in SQLite.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Riddhish.Chaudhari
  • 833
  • 1
  • 8
  • 24