-- 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. AFNetworking3.0+MBProgressHUD二次封装,一句话搞定网络提示

    对AFNetworking3.0+MBProgressHUD的二次封装,使用更方便,适用性非常强: 一句话搞定网络提示: 再也不用担心网络库更新后,工程要修改很多地方了!网络库更新了只需要更新这个封装 ...

  2. redis研究之watch

    具体的看注释,代码如下: public static void TransTest() { RedisClient client1 = new RedisClient(host, port); Red ...

  3. Poj 2115 C Looooops(exgcd变式)

    C Looooops Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22704 Accepted: 6251 Descripti ...

  4. Shell脚本——DNS自动部署

    详细说明查看: (一)跟我一起玩Linux网络服务:DNS服务——BIND(/etc/named.conf./var/named)设置实现和解释 #! /bin/bash IP="10.10 ...

  5. PHP实现斐波那契数列非递归方法

    斐波那契数列,又称黄金分割数列,指的是这样一个数列:0.1.1.2.3.5.8.13.21.……在数学上,斐波纳契数列以如下被以递归的方法定义:F0=0,F1=1,Fn=F(n-1)+F(n-2)(n ...

  6. PHP 面向对象之自定义类

    所谓面向对象就是什么时候什么东西做什么,我们设计类的时候需要想的就是怎么做的内容,那么怎么样的一个类才算是符合OOP的思想呢,答案是:这个类写好之后,在使用的过程中,能准确的代表一个事物,在书写的时候 ...

  7. Python全栈开发之 Mysql (一)

    一: 1.什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库别说我们在写程序的时候创建的database就是一个数据库 2.什么是 MySQL.Oracle.SQLi ...

  8. web2.0最全的国外API应用集合

    web2.0最全的国外API应用集合 原文地址:http://www.buguat.com/post/98.html 2.0时代,越来越多的API被大家广泛应用,如果你还不了解API是何物,请看这里的 ...

  9. yarn资源管理器高可用性的实现

    资源管理器高可用性 . The ResourceManager (RM) is responsible for tracking the resources in a cluster, and sch ...

  10. Android中通过访问本地相册或者相机设置用户头像

    目前几乎所有的APP在用户注册时都会有设置头像的需求,大致分为三种情况: (1)通过获取本地相册的图片,经过裁剪后作为头像. (2)通过启动手机相机,现拍图片然后裁剪作为头像. (3)在APP中添加一 ...