【问题标题】:While selecting date from databse I want to add 5:30 to created_at date in the database从数据库中选择日期时,我想将 5:30 添加到数据库中的 created_at 日期
【发布时间】:2019-06-05 07:13:19
【问题描述】:

我的 Sql 服务器存在于 UTC。当我选择时,我想获取添加了+5:30 的日期。

select cl.ChangeStatus,cl.created_at from LogTable cl join  Table t on cl.Id=t.ID;


ChangeStatus     created_at
----------------------------------
submitted   2019-01-10 08:03:11
sent        2019-01-10 08:06:55
sent        2019-01-10 08:08:14
sent        2019-01-10 08:09:03
complete    2019-01-10 08:09:54 

ChangeStatus   created_at
--------------------------------
submitted   2019-01-10 12:33:11
sent        2019-01-10 12:36:55
sent        2019-01-10 12:38:14
sent        2019-01-10 12:39:03
complete    2019-01-10 12:39:54

【问题讨论】:

  • 是mysql还是sql server相关?删除一个不相关的标签。
  • 使用 Todatetimeoffset 函数来实现。
  • 对不起,我错误地添加了SQL Server,我目前正在使用MySql
  • 如果是Mysql,试试这个链接:stackoverflow.com/questions/2187593/…

标签: mysql


【解决方案1】:

以下查询应该可以解决问题:

select
cl.ChangeStatus,
Todatetimeoffset(cl.created_at, '+5:30') as created_at
from LogTable cl
join  Table t on cl.Id=t.ID;

【讨论】:

    猜你喜欢
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 2016-07-19
    • 2017-12-20
    • 2015-08-21
    相关资源
    最近更新 更多