当前位置: 动力学知识库 > 问答 > 编程问答 >

php - MySQL query to get items within range of two datetimes while working with something greater than or equal to the begining of the range

问题描述:

I have two fields in my DB table a start_time and and end_time example:

start_time: 2013-04-20 13:07:00

end_time: 2013-04-20 12:07:00

my query currently contains

 where `start_time` >= '2013-04-20 14:13:20' AND `end_time` <= '2013-04-20 18:13:20'

which due to the way the query is the start_time: 2013-04-20 13:07:00 will not pull in the result so I am seeking idea of how to compensate for that. The time thats generated for the pull already sets the time back an hour from the current time, and sets the end time to 4 hours from the current time.

网友答案:

don't use >= and <= in query use some thing like this to fix it. where (start_time > '2013-04-20 14:13:20' or start_time = '2013-04-20 14:13:20' ) AND (end_time < '2013-04-20 18:13:20' or end_time = '2013-04-20 18:13:20')

分享给朋友:
您可能感兴趣的文章:
随机阅读: