'DATE' is not a recognized built-in function name
Solution 1
As the error states, there is no DATE
function in SQL Server 2008 or 2012 (you tagged both so I'm not sure which you're targeting). You can, however, cast to a date
type in SQL Server 2008 and above:
WHERE EnterDate = CONVERT(date,GETDATE())
Note that there's no CURDATE
function either, so I've translated that to GETDATE()
Solution 2
Use the following condition in your where cluase
WHERE CAST(DateColumn AS DATE) = CAST(GETDATE() AS DATE)
^------------ Your Column Name with `Date` or 'DateTime' data type
CURDATE()
is a mysql function, In Sql-Server we have GETDATE()
function to get current date and time.
Solution 3
More efficient one is
WHERE EnterDate > DATEADD(dd, -1, DATEDIFF(dd, 0, GETDATE()))
Thanks @D Stanley @marc_S and @Mihai
Engineer M Sajjad
Software Professional having 8+ years’ experience in developing high end complex Web and Cloud Solutions. Skilled in all phases of the software development life-cycle; expert in translating business requirements into technical solutions; Very enthusiastic about quality, usability, security and scalability.
Updated on September 28, 2020Comments
-
Engineer M Sajjad over 3 years
I wish to find all records of the current day. I have a field Date of type DATE. I am getting error on sql server
'DATE' is not a recognized built-in function name.
on this line
(DATE(EnterDate) = CURDATE() )
-
Lamak over 10 years"I have a field Date of type DATE", means no need to cast the column to a
DATE
-
M.Ali over 10 years@Lamak I understand that but when a user is trying to use 'CURDATE()' function to get today's date, I find it diffcult to believe that the column he claims to have in
DATE
data type is really in Date data type :) -
M.Ali over 10 yearsI know for a fact using
CAST()
function on a date data type column allows your query to be Sargable is it also true in case ofCONVERT()
function ?? -
D Stanley over 10 yearsI do not no it for a fact but since
CAST
andCONVERT
work the same for date/datetime types then it should make no difference. -
M.Ali over 10 yearsconstructive criticisim : please have a look here msmvps.com/blogs/robfarley/archive/2010/01/22/…
-
D Stanley over 10 years@M.Ali that example shows using
CONVERT
to go from a datetime to a character type, whereCONVERT
does work differently (by supporting multiple formats) and apparently is NOT SARGable. Accouring to this answer conversion fromdatetime
todate
is sargable. -
M.Ali over 10 yearsThank you for the link and the explanation.