0

I am trying to get data between date range. Date is saved as TEXT in my database (dd-MM-YYYY format) When I fire the below query results are null.

SELECT * FROM appointment_table WHERE date BETWEEN cast( '08-02-2017' as datetime ) AND cast( '16-02-2017' as datetime ) AND barber_id = 36

The correct way for getting data between date ranges when date is saved in TEXT format irrespective of the date format is as below

SELECT * FROM appointment_table WHERE date BETWEEN '08-02-2017' AND '16-02-2017' AND barber_id = 36
Maheshwari Reddy
  • 677
  • 1
  • 7
  • 16

1 Answers1

3

You need to use one of the format supported by SQLite described here to use BETWEEN: http://www.sqlite.org/lang_datefunc.html

So your query should become: (transform DD-MM-YYYY strings to YYYY-MM-DD date)

SELECT * FROM appointment_table WHERE barber_id = 36 AND (date BETWEEN '2017-02-08' AND '2017-02-16')
MatPag
  • 41,742
  • 14
  • 105
  • 114