55

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)?

1 Answer 1

70

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
1
  • 15
    There is also SYSUTCDATETIME() to complement GETUTCDATE(). Commented Jan 28, 2013 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.