Anki
Anki

Reputation: 589

How can I get all data between two dates from sqlite database?

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?

Upvotes: 1

Views: 5207

Answers (3)

Riddhish.Chaudhari
Riddhish.Chaudhari

Reputation: 853

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

Upvotes: 0

Hector
Hector

Reputation: 3907

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'

Upvotes: 2

Hanon
Hanon

Reputation: 3927

  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

Upvotes: 0

Related Questions