TIME (TSQL Datatype)
Stores the time in a day.
Syntax
TIME
Range
00:00:00 to 23:59:59.999999999
Literal Time
There is no syntax for writing a literal
time
.
You just use a literal string, and it will be converted to time
.
The format to write a literal time
is 'HH:mm:ss.fffffffff'
, where seconds and fraction of seconds can be omitted.
Examples
DECLARE @a TIME = '23:00';
DECLARE @b TIME = '4:5';
DECLARE @c TIME = '17:30';
DECLARE @d TIME = '17:30:15';
DECLARE @e TIME = '17:30:15.123';
DECLARE @f TIME = '17:30:15.123456789';
DECLARE @g TIME = '1989-03-02'; -- time is 00:00:00
DECLARE @h TIME = '19890302 09:30:00'; -- date part is ignored
DECLARE @i TIME = '';
PRINT @a;
PRINT @b;
PRINT @c;
PRINT @d;
PRINT @e;
PRINT @f;
PRINT @g;
PRINT @h;
PRINT @i;
The result is:
23:00:00
04:05:00
17:30:00
17:30:15
17:30:15.123000000
17:30:15.123456789
00:00:00
09:30:00
00:00:00