Never use GetDate() when comparing date timesoffsets, use SYSDATETIMEOFFSET()
-- my current uk time is 2014-01-09 10:43:00 +0
DECLARE @userLocalTimeChina datetimeoffset(4) = '2014-01-09 18:43:00 +08:00';
DECLARE @userLocalTimeLasVagas datetimeoffset(4) = '2014-01-09 02:43:00 -08:00';
DECLARE @userUTCTime datetimeoffset(4) = '2014-01-09 10:43:00 +00:00';
Declare @systemDateTimeOffsetWhereServerInUK datetimeoffset(4) = SYSDATETIMEOFFSET();
Declare @systemDateTimeWhereServerInUK datetime = GETDATE();
print @systemDateTimeOffsetWhereServerInUK
print @systemDateTimeWhereServerInUK
-- for demo, it gives this
SET @systemDateTimeOffsetWhereServerInUK = '2014-01-09 10:43:00 +00:00';
SET @systemDateTimeWhereServerInUK = '2014-01-09 10:43:00'
Declare @systemDateTimeOffsetWhereServerInNY datetimeoffset(4) = '2014-01-09 05:43:00 -05:00';
Declare @systemDateTimeWhereServerInNY datetime = '2014-01-09 05:43:00';
-- ALL THESE TIMES should be the same.
--Using HOURS here to show the difference, but if we usually use DAYS, this simply means people can 'see' things or 'where clauses' go wrong at certain hours of the day
print 'Compare user LOCAL time to server offset and not offset date time, in uk then new york'
print DATEDIFF(HH, @userLocalTimeChina, @systemDateTimeOffsetWhereServerInUK); -- Correct
print DATEDIFF(HH, @userLocalTimeChina, @systemDateTimeWhereServerInUK); -- The result is correct, but only because server is in UK and no daylight savings time, so will be INCORRECT and CORRECT depending on time of year!!!
print DATEDIFF(HH, @userLocalTimeChina, @systemDateTimeOffsetWhereServerInNY); -- CORRECT
print DATEDIFF(HH, @userLocalTimeChina, @systemDateTimeWhereServerInNY); -- INCORRECT RESULT
print 'Compare user UTC time to server offset and not offset date time, in uk then new york'
-- compare Users UTC time offset with system offset produces CORRECT result most of the time, in the uk
print DATEDIFF(HH, @userUTCTime, @systemDateTimeOffsetWhereServerInUK); -- CORRECT
print DATEDIFF(HH, @userUTCTime, @systemDateTimeWhereServerInUK); -- The result is correct, but only because server is in UK and no daylight savings time, so will be INCORRECT and CORRECT depending on time of year!!!
print DATEDIFF(HH, @userUTCTime, @systemDateTimeOffsetWhereServerInNY); -- CORRECT
print DATEDIFF(HH, @userUTCTime, @systemDateTimeWhereServerInNY); -- INCORRECT RESULT
--CONCLUSION: ALWAYS COMPARE OFFSET TO OFFSET. OR UTCDATETIME TO UTCDATETIME. otherwise it's totaly dependant on the deploy location time zone if the solution will work.
Never use GetDate() when comparing date timesoffsets, use SYSDATETIMEOFFSET()的更多相关文章
- 【Swift】日期比较函数 记录下 Comparing date in Swift
Add this code to your project and comparing dates is easier than ever 扩展NSDATE //swift 3.0.2 extensi ...
- JavaScript Date对象
本篇主要介绍 Date 日期和时间对象的操作. 目录 1. 介绍:阐述 Date 对象. 2. 构造函数:介绍 Date 对象的构造函数new Date()几种方式. 3. 实例方法:介绍 Date ...
- Java 时间类-Calendar、Date、LocalDate/LocalTime
1.Date 类 java.util.Date是一个"万能接口",它包含日期.时间,还有毫秒数,如果你只想用java.util.Date存储日期,或者只存储时间,那么,只有你知道哪 ...
- 时间格式转换—将后台返回的/Date(1448954018000)/格式转换为正常的时间格式
用JS实现方法: function ChangeDateFormat(cellval) { )); < ? ) : date.getMonth() + ; ? " + date.get ...
- Javascript格式化json返回的时间(/Date(1482747413000)/)
//时间处理,类似/Date(1482747413000)/的形式,得到xxx年xx月xx日 11:11:11 function ChangeDateFormat(jsondate) { jsonda ...
- #9.6课堂JS总结#变量作用域 date()对象 math()对象
一.变量的作用域 1.JavaScript的作用域链 首先看下下面这段代码: <script type="text/javascript"> var rain = 1; ...
- JS date常用代码积累
Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+& ...
- JSON.stringify转换Date不正确的解決方法
JSON.stringify转换Date不正确的原因:国际时区(UTC)和中国时区(GMT)的原因,东八区+8等于国际时区. 解决方法,重新Es5的Date.prototype.toJSON方法,代码 ...
- js中转换Date日期格式
在javascript中直接输出Date得到的结果是这样的: function date(){ var date = new Date(); alert(date); } 结果是:Mon Jun 15 ...
随机推荐
- call与apply的区别
/** * 用 add 来替换 sub,add.call(sub,3,1) == add(3,1) ,所以运行结果为:alert(4); */ function add(a,b){ alert(a+b ...
- jquery 文本框失去焦点显示提示信息&&单击置空文本框
1.<textarea rows="4" placeholder="请输入提醒内容"></textarea> 2. /** * @par ...
- HDU 2089 不要62(数位DP)
不要62 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了, ...
- android软件开发之webView.addJavascriptInterface循环渐进【一】
本篇文章由:http://www.sollyu.com/android-software-development-webview-addjavascriptinterface-cycle-of-gra ...
- Python之实现一个简易计算器
自己动手写计算器 一.功能分析 用户输入一个类似这样 3*( 4+ 50 )-(( 100 + 40 )*5/2- 3*2* 2/4+9)*((( 3 + 4)-4)-4) 这样的表达式,假设表达式里 ...
- apache基本安装配置
1.安装apache 1.安装 wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.2.31.tar.gz 2.安装zlib yum install ...
- windows平台 culture name 详细列表
点击打开链接http://msdn.microsoft.com/zh-cn/goglobal/bb896001.aspx LCID Culture Identifier Culture Name Lo ...
- jquery禁用a标签,jquery禁用按钮click点击
jquery禁用a标签方法1 $(document).ready(function () { $("a").each(function () { var textValue = $ ...
- http协议请求规则与dotNet的解析
请求方法URI协议/版本 请求的第一行是"方法URL议/版本":GET/sample.jsp HTTP/1.1 以上代码中"GET"代表请求方法,"/ ...
- OC中格式化输出符号
定义 说明 %@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, ...