56

According to MSDN, Getdate(), GetUtcDate(), and CURRENT_TIMESTAMP all return DATETIME. I ran a short test, which confirms that:

CREATE TABLE #t(T DATETIME2(7));
GO

DECLARE @i INT ;
SET @i=1;

WHILE @i<10000 BEGIN ;
INSERT #t VALUES(CURRENT_TIMESTAMP) ;
SET @i=@i+1;
END ;

SELECT DISTINCT t 
FROM #t 
ORDER BY t ;

---

2013-01-28 13:23:19.4930000
2013-01-28 13:23:19.4970000
2013-01-28 13:23:19.5000000
2013-01-28 13:23:19.5030000
2013-01-28 13:23:19.5070000
2013-01-28 13:23:19.5100000
2013-01-28 13:23:19.5130000

(snip)

Is there a similar function that returns DATETIME2(7)?

A-K
  • 7,444
  • 3
  • 35
  • 52

1 Answers1

72

SYSDATETIME returns a DATETIME2 object.

CREATE TABLE #t(T DATETIME2(7));
GO

DECLARE @i INT ;
SET @i=1;

WHILE @i<10000 BEGIN ;
INSERT #t VALUES(SYSDATETIME()) ;
SET @i=@i+1;
END ;

SELECT DISTINCT t 
FROM #t 
ORDER BY t ;



2013-01-28 12:34:28.2514394
2013-01-28 12:34:28.2670399
2013-01-28 12:34:28.2826404
2013-01-28 12:34:28.2982409
2013-01-28 12:34:28.3138414
2013-01-28 12:34:28.3294419
2013-01-28 12:34:28.3450424
2013-01-28 12:34:28.3606429
2013-01-28 12:34:28.3762434
2013-01-28 12:34:28.3918439
2013-01-28 12:34:28.4074444
2013-01-28 12:34:28.4230449
2013-01-28 12:34:28.4386454
2013-01-28 12:34:28.4542459
2013-01-28 12:34:28.4698464
swasheck
  • 10,755
  • 5
  • 48
  • 89