-- 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()的更多相关文章

  1. 【Swift】日期比较函数 记录下 Comparing date in Swift

    Add this code to your project and comparing dates is easier than ever 扩展NSDATE //swift 3.0.2 extensi ...

  2. JavaScript Date对象

    本篇主要介绍 Date 日期和时间对象的操作. 目录 1. 介绍:阐述 Date 对象. 2. 构造函数:介绍 Date 对象的构造函数new Date()几种方式. 3. 实例方法:介绍 Date ...

  3. Java 时间类-Calendar、Date、LocalDate/LocalTime

    1.Date 类 java.util.Date是一个"万能接口",它包含日期.时间,还有毫秒数,如果你只想用java.util.Date存储日期,或者只存储时间,那么,只有你知道哪 ...

  4. 时间格式转换—将后台返回的/Date(1448954018000)/格式转换为正常的时间格式

    用JS实现方法: function ChangeDateFormat(cellval) { )); < ? ) : date.getMonth() + ; ? " + date.get ...

  5. Javascript格式化json返回的时间(/Date(1482747413000)/)

    //时间处理,类似/Date(1482747413000)/的形式,得到xxx年xx月xx日 11:11:11 function ChangeDateFormat(jsondate) { jsonda ...

  6. #9.6课堂JS总结#变量作用域 date()对象 math()对象

    一.变量的作用域 1.JavaScript的作用域链 首先看下下面这段代码: <script type="text/javascript"> var rain = 1; ...

  7. JS date常用代码积累

    Date.prototype.Format = function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+& ...

  8. JSON.stringify转换Date不正确的解決方法

    JSON.stringify转换Date不正确的原因:国际时区(UTC)和中国时区(GMT)的原因,东八区+8等于国际时区. 解决方法,重新Es5的Date.prototype.toJSON方法,代码 ...

  9. js中转换Date日期格式

    在javascript中直接输出Date得到的结果是这样的: function date(){ var date = new Date(); alert(date); } 结果是:Mon Jun 15 ...

随机推荐

  1. mkisofs出错解决办法

    使用mkisofs遇到错误: genisoimage: Uh oh, I cant find the boot catalog directory 'beini/boot/isolinux'! 使用的 ...

  2. Quartz2.2.1操作手册

    一.初识quartz JobDetail job = newJob(HelloJob.class).withIdentity("job1", "group1") ...

  3. 09_Mybatis开发Dao方法——mapper代理开发规范

    一.开发规范 需要编写mapper.xml映射文件(本项目为userMapper.xml,类似于前面的user.xml). 编写mapper接口需要遵循一些开发规范,这样MyBatis可以自动生成ma ...

  4. IDC机房动力环境设备维护

    高低压配电                                              空调                                               ...

  5. ASP.NET中的Request、Response、Server对象

    Request对象 Response.Write(Request.ApplicationPath) //应用根路径 Request.AppRelativeCurrentExecutionFilePat ...

  6. HTTP_USER_AGENT

    <!DOCTYPE html><html><head><meta charset="UTF-8" /><title>We ...

  7. wcf通道Channel

    正文 客户端与服务进行交互的过程是通过通道进行交互的.客户端通过调用代理类执行相应的方法,通过通道编码,调用上下文,传输客户端的事务,管理可靠会话,对消息正文的加密,最后要执行的通道是传输通道就像我们 ...

  8. Sql中Rank排名函数

    A.对分区中的行进行排名 以下示例按照数量对指定清单位置的清单中的产品进行了排名. 结果集按 LocationID 分区并在逻辑上按 Quantity 排序. 注意,产品 494 和 495 具有相同 ...

  9. STM32之系统滴答定时器

    一.SysTick(系统滴答定时器)概述 操作系统需要一个滴答定时器周期性产生中断,以产生系统运行的节拍.在中断服务程序里,基于优先级调度的操作系统会根据进程优先级切换任务,基于时间片轮转系统会根据时 ...

  10. 进位位(carry)与溢出位(overflow)的区别

    处理器内部以补码表示有符号数,8个二进制位能够表达的整数范围是:+127 ~ -128,16位表达的范围是:+32767 ~ -32768.如果运算结果超出了这个范围,就是产生了溢出:有溢出,说明有符 ...