0

In my app I have to fetch list of all rows if enrollDate is less or equal to current date .

my SQLite query is as

select * from master  where enrollDate<='current date'

enroll date in table is "07/21/2017" and current date is "11/22/2017" .

Everything works well and I get list of rows if current date is till '30/09/2017' but when current date start from "10/01/2017" then list is returned with 0 rows while its also later date.

Please tell me why it is happening and how to resolve it.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69

2 Answers2

1

You are actually comparing strings, not dates. Strings compare lexicographically.

To compare dates in SQL, consider storing them in a format where lexicographical and temporal ordering are the same. For example, ISO 8601 UTC stamps yyyy-MM-dd or Java's long epoch milliseconds.

laalto
  • 150,114
  • 66
  • 286
  • 303
0
SELECT * FROM master WHERE CAST(strftime('%s', enrollDate)  AS  integer) <=CAST(strftime('%s', currentDate)  AS  integer) ;
Faisal Naseer
  • 4,110
  • 1
  • 37
  • 55