0

I need to check the date in the range from_date and to_date.

Ex) Employee applies leave from 2012-11-08 to 2012-11-09, here I need to check 2012-11-08 with the date range includes the from_date and to_date.

Please suggest me to use the proper queries to get the records.

When I use Mysql BETWEEN, it checks the date in between range only and not including the from_date and to_date.

nkdweb
  • 13
  • 1
  • 10

2 Answers2

0

use a comparison operator:

WHERE from_date >= '2012-11-08' AND to_date <= '2012-11-08'

Konstantin
  • 493
  • 3
  • 4
0

BETWEEN in MySQL is inclusive, which means that 2012-11-08 falls within the range of 2012-11-08 - 2012-11-09. Your problem is probably the TIME part.

Try casting the database fields to date in your query and see what result you get, i.e.:

SELECT x FROM y WHERE '2012-11-08' BETWEEN DATE(date_from) AND DATE(date_until)

Sherlock
  • 7,525
  • 6
  • 38
  • 79