MYSQL-在请求中比较NOW()和巴黎TimeZone中的日期 [英] MYSQL - Compare NOW() and a date at Paris TimeZone in a request
问题描述
我有一个存储为DateTime(巴黎日期时间)的值.
在视图中,如何才能知道存储的日期是否早于或等于NOW(),而在任何情况下都可以在巴黎时区使用NOW()?
I have a value stored as a DateTime (Paris date-time).
How can I, into a VIEW, know if a stored date is before or equal to NOW(), with NOW() at Paris TimeZone in any case?
PS:我对SQL Server没有任何控制.
PS : I do not have any control over the SQL server.
推荐答案
To Ensure that the date is in paris time zone you can use CONVERT_TZ
to convert between time zones. For example the following query will compare the NOW()
date with the stored date and gives you the difference (in days) between them, ensuring that the two dates are in a specific time zone, (I don't know the time zone of paris but this is just an example):
select datediff(
Convert_TZ(Now(),"SYSTEM","-08:00"),
Convert_Tz(AddedIn,"SYSTEM","-08:00")
)
from TableName
System
返回您的当前时区,并且由于-08:00
是要转换为时区的时区,因此可以使用时区的名称,也可以使用指定的时区名
System
returns your current time zone, and for -08:00
is the time zone that you want to convert to as an offset, you can use the name of the time zone or it's offset as specified MySQL Time zone design pattern.
希望这会有所帮助;
这篇关于MYSQL-在请求中比较NOW()和巴黎TimeZone中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!