查找日期范围内的所有内容 [英] Find all in dates range

查看:47
本文介绍了查找日期范围内的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 MySQL 的住宿表,其中每个住宿都用 from_dateto_date 列定义.我想找到用户定义的范围内的所有停留.例如,假设从 01.01.201501.03.2015 有一段停留,我希望此条目包含在 01.01.2015 的报告中> 到 31.01.2015 以及从 01.02.201528.02.2015 和在 01.03.2015 到 <代码>31.03.2015.我已将所有内容存储为时间戳(以秒为单位).有人可以举例说明如何实现这一点吗?

I've got a MySQL table of stays, where each stay is defined with a from_date and to_date column. And I want to find all stays in range defined by user. For example, given that there is a stay from 01.01.2015 to 01.03.2015 I want this entry to be included in reports from 01.01.2015 to 31.01.2015 but also from 01.02.2015 to 28.02.2015 and in 01.03.2015 to 31.03.2015. I've got everything stored as timestamps (in seconds). Could somebody, please, give an example how to achieve this?

推荐答案

好的,感谢其他答案,我得到了最好的结果<代码>(stay_range_start<=selected_range_end) &&(stay_range_end>=selected_range_start) 在 mysql 中:

Ok, thanks to the other answers I got the best results with (stay_range_start<=selected_range_end) && (stay_range_end>=selected_range_start) in mysql:

SELECT * FROM stays
WHERE  `t0`.`from_date` <= $to_date 
AND `t0`.`to_date` >= $from_date

这篇关于查找日期范围内的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆