将datetime转换为UTC值mssql [英] convert datetime to UTC value mssql

查看:177
本文介绍了将datetime转换为UTC值mssql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的查询:

SELECT table.a, table.b, table.c from Table table

我可以如何将table.b转换为UTC时间,只需将CAST添加到查询中?

How i can cast "table.b" to UTC time just adding CAST into the query?

SELECT 
  table.a, 
  **%CAST_TO_UTC_FUNCTION to table.b%**, 
  table.c 
from Table table

我无法分别投放,并声明

I'm not able to cast it separately and declaring local variables.

推荐答案

您可以按如下方式编写您的查询:

You can write your query as follows:

SELECT 
  table.a, 
  dateAdd(
    second,
    dateDiff(second, getDate(), getUtcDate()),
    table.b) as b_converted_to_UTC,
  table.c 
from Table table

将列 b 中的值转换为UTC,通过将当前日期( getDate()之间的tmie差异添加到这些值) )和UTC日期( getUtcDate())。

This converts the values in column bto UTC, by adding to those values the tmie difference that currently exists between the local date (getDate()) and the UTC date (getUtcDate()).

为了使上述查询工作,以下内容必须为真:

In order for the above query to work, the following must be true:


  • 存储在 b 列中的日期必须在当地时间表示

  • 服务器日期/时区应正确配置

  • the date(s) stored in column b must be expressed in local time
  • the server date/time zone should be properly configured

这篇关于将datetime转换为UTC值mssql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆