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

前端 未结 5 568
小蘑菇
小蘑菇 2021-01-05 05:12

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 funct         


        
相关标签:
5条回答
  • 2021-01-05 05:26

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

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

    0 讨论(0)
  • 2021-01-05 05:34

    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()

    0 讨论(0)
  • 2021-01-05 05:34

    Finally I get it done by
    WHERE EnterDate > Convert(DATETIME,Convert(varchar,DATEADD(DAY,0,GETDATE()),101))

    0 讨论(0)
  • 2021-01-05 05:41

    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.

    0 讨论(0)
  • 2021-01-05 05:46

    More efficient one is

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

    Thanks @D Stanley @marc_S and @Mihai

    0 讨论(0)
提交回复
热议问题