Msg 195, Level 15, State 10, Line 6 'Datetime' Is Not a Recognized Built-in Function Name

I am getting the error while running this query

declare @currentDate datetime
set @currentDate = getdate()
select count(Id) 
    from dbo.tblLstOfClientHolidays 
    where Datetime(@currentDate) = CONVERT(VARCHAR(10),getdate(ClientHoldiday),10)
1

2 Answers

Select  
    count(Id) 
From    
    dbo.tblLstOfClientHolidays 
Where   
    CONVERT(VARCHAR(10),ClientHoldiday,10) = CONVERT(VARCHAR(10),@currentDate,10)
2

Since you are using SQL Server 2008, You can even CONVERT to DATE rather than converting to a VARCHAR and then doing a comparison.

DECLARE @currentDate DATE;
SET @currentDate = GETDATE();

SELECT count(Id) 
FROM dbo.tblLstOfClientHolidays 
WHERE CONVERT(DATE,@currentDate) = CONVERT(DATE,ClientHoldiday);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest