SQL GetUtcDate与GetDate Quesion [英] SQL GetUtcDate Vs GetDate Quesion

查看:130
本文介绍了SQL GetUtcDate与GetDate Quesion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想我知道答案,但我只是想要第二意见。



我已经从VM写入数据库的应用程序,日期时间戳似乎使用UTC时间 - 所以目前在英国,时钟返回1小时夏令时



所以上午8点进入早上7点,但是我有另一个应用程序从数据库中提取信息,但是使用我用sql编写的提取器显示不同步。



所以我的问题是:

'GetUTCTime()'函数是否总是返回没有夏令时的基准时间,因为我现在需要进行更改,但我不想让它搞砸了时钟又回来了,我用它来调整SQL select语句的时间戳。



请你确认它是否会在时钟返回时发挥作用,它现在我们在夏令时工作。



Hi,

I think i know the answer but i just wanted second opinion.

An application i have writes to a database from a VM, the datetime stamps appear to go in using UTC time - so currently in UK the clocks went back 1 hour for daylight savings time

so an 8am entry goes in at 7am however i have another application that pulls information out of the database but showing out of sync using an extractor i wrote using sql.

so my question here is:
Does 'GetUTCTime()' function always return the base time without daylight savings time as i need to make the change now but i dont want it to mess up when the clocks go back again, i am using this to adjust the timestamp on the SQL select statement.

Please can you confirm if it will do the trick when the clocks go back, it works now that we are in DST.

DECLARE @DSTTIME AS TIME = 
	(CASE 
		WHEN DATEDIFF(HOUR, GetUtcDate(), GetDate()) = 1 
		THEN CONVERT(datetime, '01:00:00',120) 
		ELSE CONVERT(datetime, '00:00:00',120) 
	END)

推荐答案

GetUTCDate返回,而不是令人惊讶的是,UTC :)(又名GMT,Zulu,TZ0等) - 它通常是'最佳实践tice'拥有SQL存储并返回UTC,并让* client * app将其解释为当地时间,避免许多问题,并使所有时间都合理
GetUTCDate returns, not suprisingly, UTC :) (aka GMT, Zulu, TZ0 etc) - it's normally 'best practice' to have SQL store and return UTC, and have the *client* app interpret that to local time, avoids lots of problems, and makes all times 'sensible'


这篇关于SQL GetUtcDate与GetDate Quesion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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