简体   繁体   中英

check arrival date and departure are within range mysql

I have following table :

id      travelStart travelExpires
1       2012-11-12  2013-01-31
1       2012-11-12  2013-01-31

and following are my arrival and departure dates:

arrival date: 2012-12-28
departure date   : 2012-12-30

I want to check that arrival and departure date in between travelStart and travelEnd date. How to write mysql query for it.

Your answer has as simplest solution the BETWEEN operator in MySQL. How it works:

SELECT * from YourTable WHERE ( :arrivalDate BETWEEN travelStart AND travelExpires) AND ( :departureDate BETWEEN travelStart AND travelExpires )

You'll obviously need to bind the :arrivalDate and :departureDate parameters.

试试这个查询

select * from table where (arrival_date<=travelStart AND arrival_date<=travelExpires) AND (departure_date>=travelStart AND departure_date<=travelExpires)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM