|
1 | 1 | --- |
2 | 2 | title: "TODATETIMEOFFSET (Transact-SQL) | Microsoft Docs" |
3 | 3 | ms.custom: "" |
4 | | -ms.date: "03/13/2017" |
| 4 | +ms.date: "04/22/2019" |
5 | 5 | ms.prod: sql |
6 | 6 | ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" |
7 | 7 | ms.reviewer: "" |
@@ -60,30 +60,27 @@ TODATETIMEOFFSET ( expression , time_zone ) |
60 | 60 | ### A. Changing the time zone offset of the current date and time |
61 | 61 | The following example changes the zone offset of the current date and time to time zone `-07:00`. |
62 | 62 |
|
63 | | -``` |
| 63 | +```sql |
64 | 64 | DECLARE @todaysDateTime datetime2; |
65 | 65 | SET @todaysDateTime = GETDATE(); |
66 | 66 | SELECT TODATETIMEOFFSET (@todaysDateTime, '-07:00'); |
67 | | --- RETURNS 2007-08-30 15:51:34.7030000 -07:00 |
| 67 | +-- RETURNS 2019-04-22 16:23:51.7666667 -07:00 |
68 | 68 | ``` |
69 | 69 |
|
70 | 70 | ### B. Changing the time zone offset in minutes |
71 | 71 | The following example changes the current time zone to `-120` minutes. |
72 | 72 |
|
73 | | -``` |
74 | | -DECLARE @todaysDate datetime2; |
75 | | -SET @todaysDate = GETDATE(); |
76 | | -SELECT TODATETIMEOFFSET (@todaysDate, -120); |
77 | | --- RETURNS 2007-08-30 15:52:37.8770000 -02:00 |
| 73 | +```sql |
| 74 | +SELECT TODATETIMEOFFSET(SYSDATETIME(), -120) |
| 75 | +-- RETURNS: 2019-04-22 11:39:21.6986813 -02:00 |
78 | 76 | ``` |
79 | 77 |
|
80 | 78 | ### C. Adding a 13-hour time zone offset |
81 | 79 | The following example adds a 13-hour time zone offset to a date and time. |
82 | 80 |
|
83 | | -``` |
84 | | -DECLARE @dateTime datetimeoffset(7)= '2007-08-28 18:00:30'; |
85 | | -SELECT TODATETIMEOFFSET (@dateTime, '+13:00'); |
86 | | --- RETURNS 2007-08-28 18:00:30.0000000 +13:00 |
| 81 | +```sql |
| 82 | +SELECT TODATETIMEOFFSET(SYSDATETIME(), '+13:00') |
| 83 | +-- RETURNS: 2019-04-22 11:39:29.0339301 +13:00 |
87 | 84 | ``` |
88 | 85 |
|
89 | 86 | ## See Also |
|
0 commit comments