2

Trying to select a date (x) days from today's date, where the date would be start of day (e.g. 12:00am that day).

For example, a query with date 5 days earlier..

@"select pkey, dateofmod from data WHERE dateofmod >= date('now', '? days')" ,  [NSNumber numberWithInt:-5]; 

doesn't seem to work. (using FMDB).

Jordan
  • 21,708
  • 10
  • 49
  • 63
  • You might find the details on this question/answer useful. http://stackoverflow.com/questions/1711504/how-get-datetime-column-in-sqlite-objecite-c/1711591#1711591 – xyzzycoder Jan 16 '10 at 08:01

2 Answers2

4

Is this what you need?

sqlite> SELECT date( julianday(date('now')));
2009-08-19
sqlite> SELECT date( julianday(date('now'))+2);
2009-08-21

julianday does "round" to midnight:

sqlite> SELECT datetime( julianday(date('now')));
2009-08-19 00:00:00
sqlite> SELECT datetime( julianday(date('now'))+2);
2009-08-21 00:00:00

Usually with SQLite you want to use julianday if you are adding a number of days to a date.

SQLite Date and Time Functions

Mark Rushakoff
  • 238,196
  • 44
  • 399
  • 395
1

You can always do select Top X.

@"select TOP X from data WHERE dateofmod >= date('now', '? days')" ,  [NSNumber numberWithInt:-5];
Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
rkb
  • 10,483
  • 22
  • 71
  • 101