mantawolf

SQL DateTypes

Apr 6th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.00 KB | None | 0 0
  1. CREATE TABLE ##table1 (
  2.     Id INT
  3.     , dateOne DATETIME -- will store miliseconds
  4.     , dateTwo DATETIME2 -- will store nanoseconds
  5.     , dateThree DATETIME2(0) -- cuts off past the second
  6.     , dateFour DATETIME2 -- can see getDate() is less precision than sysDateTime()
  7.     , dateFive DATE -- new date type, stores only the date part
  8.     , timeOne TIME -- new time type, stores only the time part down to nanoseconds
  9.     , timeTwo TIME(0) -- time type storing only down to the seconds
  10. );
  11. INSERT INTO ##table1 (
  12.     Id
  13.     , dateOne
  14.     , dateTwo
  15.     , dateThree
  16.     , dateFour
  17.     , dateFive
  18.     , timeOne
  19.     , timeTwo
  20. )
  21. VALUES (
  22.     1
  23.     , sysdatetime() -- DATETIME - 2015-04-03 14:06:46.323
  24.     , sysdatetime() -- DATETIME2 - 2015-04-03 14:06:46.3235366
  25.     , sysdatetime() -- DATETIME2(0) - 2015-04-03 14:06:46
  26.     , getdate() -- DATETIME2 - 2015-04-03 14:06:46.3170000
  27.     , sysdatetime() -- DATE - 2015-04-03
  28.     , sysdatetime() -- TIME - 14:06:46.3235366
  29.     , sysdatetime() -- TIME(0) - 14:06:46
  30. )
  31.  
  32. SELECT * FROM ##table1
  33.  
  34. DROP TABLE ##table1
Advertisement
Add Comment
Please, Sign In to add comment