简体   繁体   中英

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. 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.

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. At 8:00pm the UTC time in the database is 00:00:00 which is less than 23:00:00 .

The field type that the start time is stored in is time

I use javascript to get the time-offset and input, and php for mySQL. Any ideas on how to solve this using those languages or SQL?

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. This is a mysql function, so all the information transform can happen on the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM