75

Using SQL Server, which is the fastest or best practice method to use for date retrieval? Is there a difference between CURRENT_TIMESTAMP and GetDate()?

TylerH
  • 20,799
  • 66
  • 75
  • 101
digiguru
  • 12,724
  • 20
  • 61
  • 87

4 Answers4

97

CURRENT_TIMESTAMP is standard ANSI SQL, and so is theoretically one tiny little island of 'don't need to change' amongst your thousands of SQL Server-specific lines of SQL if you ever need to move databases....

ahsteele
  • 26,243
  • 28
  • 134
  • 248
Cowan
  • 37,227
  • 11
  • 66
  • 65
34

CURRENT_TIMESTAMP is part of the ANSI SQL spec. GETDATE() is a SQL Server-specific function inherited from the original Sybase code on which SQL Server is based.

They do exactly the same thing, though.

ahsteele
  • 26,243
  • 28
  • 134
  • 248
Dylan Beattie
  • 53,688
  • 35
  • 128
  • 197
12

My vote is for CURRENT_TIMESTAMP for 'portability' reasons i.e. why be SQL Server -specific when there is a direct SQL-92 equivalent?

PS why was it not named getdatetime()? Now that SQL Server 2008 has a DATE and TIME data type, we can hope to get support for SQL-92's CURRENT_DATE and CURRENT_TIME, at which point getdate() could be potentially even more confusing.

onedaywhen
  • 55,269
  • 12
  • 100
  • 138
9

Books Online tells us that CURRENT_TIMESTAMP "is equivalent to GETDATE()".

ahsteele
  • 26,243
  • 28
  • 134
  • 248
ila
  • 4,706
  • 7
  • 37
  • 41