MYSQL - Compare NOW() and a date at Paris TimeZone in a request

自古美人都是妖i 提交于 2019-12-22 10:19:25

问题


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 : I do not have any control over the SQL server.


回答1:


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

Hope this will help;



来源:https://stackoverflow.com/questions/8304174/mysql-compare-now-and-a-date-at-paris-timezone-in-a-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!