【发布时间】:2014-03-25 16:14:00
【问题描述】:
我正在为我的项目开发类似日历的功能。
我有一个如下表:
ID | Title |Where |tri| Start | End | tro
______________________________________________________________________
"4"|"Planingfrenzy" |"Street 8"|"0"|"1395835200"|"1395846000"|"1"
"5"|"Other meeting" |"Road 8" |"0"|"1395140400"|"1395158400"|"1"
"6"|"Third meeting" |"Lane 8" |"0"|"1395819000"|"1395824400"|"1"
"8"|"Weekend at cyprus"|"Cyprus" |"0"|"1395928800"|"1396162800"|"1"
我在选择一天内发生的所有事件时遇到问题。 我尝试了以下两个查询,但它们只返回在同一天开始和结束的那些事件。
/*
Start is a unixtimestamp for the beginning of the day
End is a unixtimestamp for the end of the day
*/
//This Returns to many events since all events that ends before the end timestamp is a match etc.
SELECT * FROM events WHERE (start > ? OR end<?)
//This matches all events that start and end at the same day. But a multi day event like "Weekend at cyprus" isn't returned since it is out of range
SELECT * FROM events WHERE (start > ? AND end<?)
如果开始/结束范围“触及”查询的时间戳范围,MySQL 或 PHP 中有什么方法可以匹配吗?
【问题讨论】:
-
?使用什么值? -
您想要某一天的所有事件(即 2015 年 3 月 7 日的所有事件)还是只持续一天的所有事件?
-
@GordonLinoff 正如评论中提到的那样? = 是当天的第一个/最后一个时间戳。
-
@AndreschSerj 我想要某个日期的所有事件。例如:我有一个从 3 月 7 日 13 点开始到 3 月 9 日 12 点结束的活动。如果我检查 3 月 8 日的活动,我仍然希望该活动出现!
标签: php mysql unix-timestamp date-range