Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
In the following code I get the error like " 'time' is not a recognised built-in function name".

SQL
SELECT YEAR(startdt) AS [Year],MONTH(startdt) AS [Month], DAY(startdt) as [day],time(startdt) as [time] COUNT(*) from visit Group By YEAR(startdt), MONTH(startdt),day(startdt),time(startdt)


The column name 'startdt' is of 'datetime' datatype.
Can anyone suggest me how to rectify this error.
Posted
Updated 1-Aug-13 0:36am
v2

 
Share this answer
 
v3
You should try this for time:
SQL
SELECT LTRIM(RIGHT(CONVERT(VARCHAR(20), GETDATE(), 100), 7))

Please read Date and Time Data Types and Functions - SQL Server (2000, 2005, 2008, 2008 R2, 2012)[^] for more details.

Hope it helps!
--Amit
 
Share this answer
 
You have to Use this...
SQL
SELECT YEAR(startdt) AS [Year],MONTH(startdt) AS [Month], DAY(startdt) as [day],Convert(Time,startdt) as [time], COUNT(*) from visit 
Group By YEAR(startdt), MONTH(startdt),day(startdt),Convert(Time,startdt)

If you want to get along with Am/Pm u have to use
SELECT RIGHT(CONVERT(VARCHAR(25), GETDATE(), 22),11)


Links: Time MSDN[^]
 
Share this answer
 
v2
I used this code:

SqlDataAdapter da = new SqlDataAdapter("seLECT YEAR(startdt) AS [Year],MONTH(startdt) AS [Month], DAY(startdt) as [day],cast(startdt as time) as [time], COUNT(*) from visit Group By YEAR(startdt), MONTH(startdt),day(startdt),startdt", con);

thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900