如何在MySQL PHP中比较两个时间列

时间:2019-08-09 06:58:40

标签: php mysql datetime time

我想使用php从mysql检查时间可用性,这是我的表

id      employeeid          booking_starttime           bookingclosetime
1       4                   1565347980                  1565349300
1       4                   1565360100                  1565364900

现在我有动态booking_start_time(1565346900)booking_end_time(1565350500),并且我想检查是否存在booking_starttime(varchar)booking_endtime(varchar) 这段时间之间的数据库又该怎么办?

2 个答案:

答案 0 :(得分:1)

看看您是否有两个时间戳,您可以像这样将它们简单地进行比较,因为它们只是数字。

Select * from table where booking_starttime < bookingclosetime

现在回答您的问题:

  

现在我有动态的booking_start_time(1565346900)和   booking_end_time(1565350500)我要检查是否   booking_starttime(varchar)和booking_endtime(varchar)存在于   在这段时间之间的数据库,那我该怎么办?

SELECT * FROM table where booking_start_time = '1565346900' AND booking_end_time = '1565350500'

答案 1 :(得分:0)

MySQL提供between关键字,它将为您执行这种操作

Select * from table where :date between start_date and end_date

https://www.techonthenet.com/mysql/between.php