T
T
tltary2016-11-22 15:56:22
MySQL
tltary, 2016-11-22 15:56:22

How does date comparison work in sql?

I have a table of 3 rows
Id date_in date_out
1 2016-11-14 2016-11-20
2 2016-11-21 2016-11-27
3 2016-11-28 2016-12-4
I am using query in SQL
select * from table where date_in>='2016-11-22' and date_out>='2016-11-22'
and it gives me line 3, although it should
have this week?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-11-22
@xpert13

Well, everything is correct 2016-11-28 >= 2016-11-22 and 2016-12-04 >= 2016-11-22.
Perhaps you wanted to find a date between date_in and date_out. Then you need to change the sign to <= in the second condition or, better, use the BETWEEN operator:

SELECT * FROM `table` WHERE '2016-11-22' BETWEEN `date_in` AND `date_out`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question