简体   繁体   English

比较mysql中的两个日期

[英]compare two date in mysql

hotel check in & check out time is 酒店入住和退房时间是

Table data 表数据

   check in                   check out                room name
2018-09-17 11:00:00           2018-09-19 11:00:00      room 1
2018-09-18 11:00:00           2018-09-19 11:00:00      room 2

Note : Standard Check in and Check out time : 11:00 AM 注意:标准入住和退房时间:上午11:00

if i try for date from 2018-09-17 11:00:00 to 2018-09-18 11:00:00 then output for that date total booked should be 1. room 1 is booked and room 2 should be free. 如果我尝试from 2018-09-17 11:00:00 to 2018-09-18 11:00:00日期from 2018-09-17 11:00:00 to 2018-09-18 11:00:00那么output for that date total booked should be 1.房间1预订,房间2应该是免费的。

my query 我的查询

SELECT * FROM transcationmaster WHERE checkin >= STR_TO_DATE('2018-09-17 11:00:00', '%Y-%m-%d %H:%i:%s') and  checkout  <= STR_TO_DATE('2018-09-18 11:00:00', '%Y-%m-%d %H:%i:%s') 

how to do this in mysql? 如何在mysql中执行此操作?

Thanks in advance 提前致谢

This is just the overlapping range problem. 这只是重叠范围问题。 To find records which overlap with your own date range, try this query: 要查找与您自己的日期范围重叠的记录,请尝试以下查询:

SELECT *
FROM transactionmaster
WHERE '2018-09-17 11:00:00' < checkout AND '2018-09-18 11:00:00' > checkin;

在此输入图像描述

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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