You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the conversion is to **time(n)**, the hour, minute, and seconds are copied. When the destination precision is less than the source precision, the fractional seconds is rounded up to fit the destination precision. The following example shows the results of converting a `time(4)` value to a `time(3)` value.
104
104
105
-
```
105
+
```sql
106
106
DECLARE @timeFrom time(4) ='12:34:54.1237';
107
107
DECLARE @timeTo time(3) = @timeFrom;
108
108
@@ -120,7 +120,7 @@ SELECT @timeTo AS 'time(3)', @timeFrom AS 'time(4)';
120
120
121
121
When the conversion is to **datetime**, hour, minute, and second values are copied; and the date component is set to '1900-01-01'. When the fractional seconds precision of the **time(n)** value is greater than three digits, the **datetime** result will be truncated. The following code shows the results of converting a `time(4)` value to a `datetime` value.
122
122
123
-
```
123
+
```sql
124
124
DECLARE @timetime(4) ='12:15:04.1237';
125
125
DECLARE @datetime datetime= @time;
126
126
SELECT @timeAS'@time', @datetime AS'@datetime';
@@ -136,7 +136,7 @@ SELECT @time AS '@time', @datetime AS '@datetime';
136
136
137
137
When the conversion is to **smalldatetime**, the date is set to '1900-01-01', and the hour and minute values are rounded up. The seconds and fractional seconds are set to 0. The following code shows the results of converting a `time(4)` value to a `smalldatetime` value.
138
138
139
-
```
139
+
```sql
140
140
-- Shows rounding up of the minute value.
141
141
DECLARE @timetime(4) ='12:15:59.9999';
142
142
DECLARE @smalldatetime smalldatetime= @time;
@@ -163,7 +163,7 @@ SELECT @time AS '@time', @smalldatetime AS '@smalldatetime';
163
163
164
164
If the conversion is to **datetimeoffset(n)**, the date is set to '1900-01-01', and the time is copied. The time zone offset is set to +00:00. When the fractional seconds precision of the **time(n)** value is greater than the precision of the **datetimeoffset(n)** value, the value is rounded up to fit. The following example shows the results of converting a `time(4)` value to a `datetimeoffset(3)` type.
@@ -180,7 +180,7 @@ SELECT @time AS '@time', @datetimeoffset AS '@datetimeoffset';
180
180
181
181
When converting to **datetime2(n)**, the date is set to '1900-01-01', the time component is copied, and the time zone offset is set to 00:00. When the fractional seconds precision of the **datetime2(n)** value is greater than the **time(n)** value, the value will be rounded up to fit. The following example shows the results of converting a `time(4)` value to a `datetime2(2)` value.
182
182
183
-
```
183
+
```sql
184
184
DECLARE @timetime(4) ='12:15:04.1237';
185
185
DECLARE @datetime2 datetime2(3) = @time;
186
186
@@ -215,7 +215,7 @@ SELECT @datetime2 AS '@datetime2', @time AS '@time';
215
215
### A. Comparing date and time Data Types
216
216
The following example compares the results of casting a string to each **date** and **time** data type.
0 commit comments