What is the SQL Server functionality that allows you to get the current date as a DATE
type like the SQL Standard's CURRENT_DATE
feature. What is the <current date value function>
for SQL Server?
Using PostgreSQL, I'm looking for something like,
SELECT CURRENT_DATE;
current_date
--------------
2018-06-27
(1 row)
Best Answer
You can use either
GETDATE
(return typedatetime
) orSYSDATETIME
(return typedatetime2
), with the difference being the precision up to nanoseconds forSYSDATETIME()
.Example:
Results:
See Date and Time Data Types and Functions (Transact-SQL) in the product documentation.
For completeness, SQL Server also recognises
CURRENT_DATE
as mentioned in the question, as an ODBC scalar function:This returns
varchar(10)
, so would need an explicit cast or convert to thedate
data type:The built-in functions are recommended over ODBC scalar functions.