Till version 2005, SQL Server supported only the datetime datatype which stored date and time with milliseconds upto three digits. However SQL Server 2008 supports separate data types DATE and TIME as well DATETIME2 datatype which stores milliseconds upto 7 digits.
You can specify the length for DATETIME2 so you can limit the number of digits
displayed for millisecond part.
You can specify the length for DATETIME2 so you can limit the number of digits
displayed for millisecond part.
You can find out the result from the output of the following queries:
select cast(getdate() as datetime2(2))
select cast(getdate() as datetime2(5))
select cast(getdate() as datetime2)
select cast(getdate() as datetime2(5))
select cast(getdate() as datetime2)
The first query limits milliseconds to 2 digits, second query limits it to 5 digits and last query will show 7 digits, as milliseconds, as no length is specified.
Also read SQL Server: DateTime vs DateTime2
1 comment:
We alaso have the ANSI/ISO Standard SQL CURRENT_TIMESTAMP instead of getdate(). The old getdate() goes back to UNIX and Sybase.
Post a Comment