-2

I want to select data between dates from a table

for eg:guestrocordtransac(tbl name)

id,roomno,roomtype, checkin,       checkout
 1  101      Baywatch  05/17/2015 05/24/2015
 2  102      BayWatch  05/10/2015 05/16/2015

when i tried writing query like this i get only one roomno as 101

SELECT roomno FROM guestrocordtransac where checkin between "05/14/2015" and "05/29/2015"
Strawberry
  • 33,750
  • 13
  • 40
  • 57
user12688
  • 71
  • 1
  • 11

1 Answers1

4

The correct answer is to fix your data so the date values are stored as date/times. It is almost always better to use native database types for values.

The second best thing (and it is a very remote second best) is to do the conversion on the fly:

SELECT roomno
FROM guestrocordtransac
where str_to_date(checkin, '%m/%d/%Y') between '2015-05-14' and '2015-05-29';

When using date constants, use the ISO standard format of YYYY-MM-DD.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786