"DATE" is not a recognized built-in function name

I want to find all the records of the current day. I have a Date field of type DATE. I get an error on sql server

'DATE' is not a recognized built-in function name. 

in this line

 (DATE(EnterDate) = CURDATE() ) 
+4
sql sql-server sql-server-2008 sql-server-2012 ssms
Jan 07 '14 at 1:47
source share
5 answers

As the error says, in SQL Server 2008 or 2012 there is no DATE function (you checked both values, so I'm not sure what you are aiming for). However, you can use the DATE type in SQL Server 2008 and later:

 WHERE EnterDate = CONVERT(date,GETDATE()) 

Note that there is no CURDATE function CURDATE , so I translated this to GETDATE()

+10
Jan 07 '14 at 1:55
source share

Use the following condition in your cluase place

 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 a GETDATE() function to get the current date and time.

+3
Jan 07 '14 at 13:51 on
source share

Finally, I do this through WHERE EnterDate> Convert (DATETIME, Convert (varchar, DATEADD (DAY, 0, GETDATE ()), 101))

0
Jan 07 '14 at 2:18
source share

More effective is

 WHERE EnterDate > DATEADD(dd, -1, DATEDIFF(dd, 0, GETDATE())) 

Thanks @D Stanley @marc_S and @Mihai

0
Jan 07 '14 at
source share

This is not an exact answer, but an example of how to trim the time part from a date time variable

CONVERT (VARCHAR (10), date_mufactured, 10) = CONVERT (VARCHAR (10), @startdate, 10))

0
Feb 08 '16 at 17:00
source share



All Articles