Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 19 down vote accepted

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
share|improve this answer
6  
There is also SYSUTCDATETIME() to complement GETUTCDATE(). –  Aaron Bertrand Jan 28 '13 at 19:36
    
+1 It works. Thanks! –  A-K Jan 28 '13 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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