简体   繁体   中英

How to make a mysql SELECT for users in a specific timezone

I have a mysql table with users, and I have a timezone field. Values can be 0 or +2 or -2, etc... for example, US users should be -5, while France users should be +1. how can I do a SELECT query (I want to run that every hour) to get all the users that are in a specific time in a specific timezone?

尝试以下

SELECT UNIX_TIMESTAMP(CONVERT_TZ(`utc_datetime`, '+02:00', @@session.time_zone)) FROM `table_name`

I found an easy solution: lets say I want to get all the users that now is 05pm in their timezone:

select * from table where SUBSTR(curtime(), -8, 2) + timezone_field = 17;

so I can run this every hour and, for example, send a message once a day at 05pm to every user.

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