Home > Database > Mysql Tutorial > body text

SQL Server本地时间和UTC时间的相互转换实现代码

WBOY
Release: 2016-06-07 18:02:05
Original
1377 people have browsed it

SQL Server 本地时间和UTC时间的相互转换的代码,需要的朋友可以参考下。

代码如下:
DECLARE @LocalDate DATETIME,
@UTCDate DATETIME,
@LocalDate2 DATETIME

SET @LocalDate = GETDATE()
SET @UTCDate = DATEADD(hour, DATEDIFF(hour,GETDATE(),GETUTCDATE()), @LocalDate)
SET @LocalDate2 = DATEADD(hour, DATEDIFF(hour,GETUTCDATE(),GETDATE()), @UTCDate)

SELECT '1. Now' [Now], @LocalDate [DateTime]
UNION
SELECT '2. UTC', @UTCDate
UNION
SELECT '3. Now again', @LocalDate2
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!