[英]Retrieve rows from SQL database after certain time
I have a table in my database that holds events. 我的数据库中有一个包含事件的表。 The events have a start time and end time.
事件具有开始时间和结束时间。 But when they are inserted into the database the time the user inputed is converted to UTC time.
但是,当将它们插入数据库时,用户输入的时间将转换为UTC时间。 So for me, my time offset is -4 hours from UTC time and if I input the start time as 7pm (19:00:00) that is converted to 23:00:00 (UTC) when added to the database.
因此,对我来说,我的时间偏移量是UTC时间的-4个小时,如果我输入的开始时间是晚上7点(19:00:00),则添加到数据库后会转换为23:00:00(UTC)。
The Problem 问题
I want the user to be able to select all events at and after 7pm until the end of the day, but If I do the query: WHERE time > 23:00:00
it will only retrieve event where the start time is between 7:00pm and 7:59pm. 我希望用户能够选择晚上7点及之后的所有事件,直到一天结束,但是如果我执行以下查询:
WHERE time > 23:00:00
,它将仅检索开始时间在7点之间的事件:下午00点和晚上7:59。 At 8:00pm the UTC time in the database is 00:00:00
which is less than 23:00:00
. 在8:00 pm,数据库中的UTC时间为
00:00:00
,小于23:00:00
。
The field type that the start time is stored in is time
开始时间存储的字段类型是
time
I use javascript to get the time-offset and input, and php for mySQL. 我使用javascript获取时间偏移和输入,并使用php for mySQL。 Any ideas on how to solve this using those languages or SQL?
关于如何使用这些语言或SQL解决此问题的任何想法?
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_convert-tz
When you pass in your local time, you can wrap it in this conversion function to convert it to UTC time. 当您传递本地时间时,可以将其包装在此转换函数中,以将其转换为UTC时间。 This is a mysql function, so all the information transform can happen on the server.
这是一个mysql函数,因此所有信息转换都可以在服务器上进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.