Php 如何为每个用户在mysql中选择与时区相关的日期时间(如果用户有不同的时区)
我有一个需要安排邮件的系统。 每个用户都有自己的时区。 我有一台服务器,服务器时区设置为Php 如何为每个用户在mysql中选择与时区相关的日期时间(如果用户有不同的时区),php,mysql,datetime,timestamp,Php,Mysql,Datetime,Timestamp,我有一个需要安排邮件的系统。 每个用户都有自己的时区。 我有一台服务器,服务器时区设置为EET。 数据库表: messages: id int not null, user_id int, schedule DATETIME DEFAULT NULL user: id name timezone: string (php compatible timezone string e.g. Europe/Paris, Europe/Budapest, etc) 所以我
EET
。
数据库表:
messages:
id int not null,
user_id int,
schedule DATETIME DEFAULT NULL
user:
id
name
timezone: string (php compatible timezone string e.g. Europe/Paris, Europe/Budapest, etc)
所以我想创建一个cron作业,每分钟检查一次数据库,并检查是否有任何需要发送的消息。
但在这里,我被这些时区困住了
我使用时区偏移量存储DateTime,如下所示:
new\DateTime('2019-01-01 01:01:01',new\DateTimeZone('Europe/Paris'))代码>
所以现在我有一个问题:
我不能使用这样的查询,因为没有检查时区
SELECT * FROM messages as m
JOIN user as u
ON u.id = m.user_id
WHERE m.schedule <= NOW() ORDER BY id DESC;
也许将其存储在UTC中,并在php端进行比较,但我认为可能有更好的解决方案
另一个解决方案是从用户中选择不同的时区
然后根据每个时区分别选择消息。@Joey Doanrauzes嗨,你可能不明白这个问题。我需要选择需要在schedule
time发送的messages
,如果schedule time@JoeYdoanRauzes Hi,您可能不明白这个问题。如果计划时间,我需要选择需要在计划
时间发送的消息
1st user timezone: `CET + 2`
2nd user timezone: `CET + 3`
server time: `CET + 5`
I need to get messages according to each users DateTime + timezone.