Sql 获取任何时区的DST开始和结束日期
我看到这个问题被问了很多次,但没有看到任何实际的答案(大多数解决方案都是针对我们时区的) 在SQL Server中,有没有一种方法可以在给定年份和时区的情况下获取夏令时的开始和结束日期 总而言之,我想看看是否有人提出了以下两个过程/功能的解决方案:Sql 获取任何时区的DST开始和结束日期,sql,sql-server,sql-server-2016,dst,Sql,Sql Server,Sql Server 2016,Dst,我看到这个问题被问了很多次,但没有看到任何实际的答案(大多数解决方案都是针对我们时区的) 在SQL Server中,有没有一种方法可以在给定年份和时区的情况下获取夏令时的开始和结束日期 总而言之,我想看看是否有人提出了以下两个过程/功能的解决方案: datetime2 getDSTStartDate(@year int, @timeZone varchar) datetime2 getDSTEndDate(@year int, @timeZone varchar) 我猜不太可能得到确切的天数。
datetime2 getDSTStartDate(@year int, @timeZone varchar)
datetime2 getDSTEndDate(@year int, @timeZone varchar)
我猜不太可能得到确切的天数。存在国家和地区差异,有些地方甚至根本不遵守DST。通常是在规定的日期和时间,但在一年中可能会发生变化。那么你的日期时间计算就无关紧要了 见该页第二段: 请注意,此列表可能不是最终列表-国家、地区和地区 州政府有时会做出调整,而调整只在几天或几天内宣布 提前几周时间改变 仅此一句话就表明内部数据库功能很容易过时,毫无意义 你可以做过去的日期,因为它们已经完成了,但如下图所示,未来的日期,虽然现在有点确定,但可能会改变,并且不可能准确预测
** Country Counts For Last 3 Years **
---------------------------------------------------------------
| **2017** |
---------------------------------------------------------------
| DST Observance |Count|Example|
---------------------------------------------------------------
|No DST at all | 172 | China |
|At least one location observes DST | 77 | USA |
|All locations observe DST some part of the year| 67 | Iran |
|Many locations observe DST part of the year | 9 | USA |
|At least one location observes DST all year | 1 | |
|All locations observe DST all year | 1 | Chile |
---------------------------------------------------------------
---------------------------------------------------------------
| **2016** |
---------------------------------------------------------------
| DST Observance |Count|Example|
---------------------------------------------------------------
|No DST at all | 171 | China |
|At least one location observes DST | 77 | USA |
|All locations observe DST some part of the year| 69 | Iran |
|Many locations observe DST part of the year | 8 | USA |
---------------------------------------------------------------
---------------------------------------------------------------
| **2015** |
---------------------------------------------------------------
| DST Observance |Count|Example|
---------------------------------------------------------------
|No DST at all | 168 | China |
|At least one location observes DST | 80 | USA |
|All locations observe DST some part of the year| 70 | Iran |
|Many locations observe DST part of the year | 9 | USA |
|At least one location observes DST all year | 1 | |
|All locations observe DST all year | 1 | Chile |
---------------------------------------------------------------
注意:由于上述种种原因,而且您还必须通过编程方式确定用户输入的位置,因此最好只将日期时间存储为UTC或其他通用格式,并根据需要使用。SQL可能不是解决所有问题的最佳场所。更有趣的是,大图末尾的一条注释写道:
*有些地点有多个DST时段:第一个时段的开始和最后一个时段的结束都会列出。
对于不进行DST的地点,该怎么办。。。像整个亚利桑那州?