[英]Adding timezone offset in the datetime in SQL
Would like to convert timestamp stored in SQL to a specific timezone.想将存储在 SQL 中的时间戳转换为特定时区。
SQL Query to offset created_at time by -33000 SQL 查询created_at时间偏移-33000
select cast(created_at - 33000 as date) from table_name
The query is working fine but it's giving NULL for timestamp 2019-11-14 02:52:31
.该查询工作正常,但它为时间戳
2019-11-14 02:52:31
。
Any hints is appreciated.任何提示表示赞赏。
Try this:尝试这个:
SQL SERVER: SQL 服务器:
Your query will cause some explicit conversion error .您的查询将导致一些显式转换错误。 So you have to convert it into proper
Datetime
, and then try you query.因此,您必须将其转换为正确的
Datetime
,然后尝试查询。
select cast(CAST('2019-11-14 02:52:31' AS DATETIME) - 33000 as date)
MySQL MySQL
You have to use DATEADD
function.您必须使用
DATEADD
function。
SELECT DATE_ADD('2019-11-14 02:52:31', INTERVAL -330 MINUTE);
The output will be 2019-11-13 21:22:31
output 将于
2019-11-13 21:22:31
Hope this will fix your issue.希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.