Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to declare datatype as time. how to declare it in while creating table in sql server 2005
Posted

SQL Server 2005 does support the DATETIME datatype, which also includes time. To store only the time, you can use the CONVERT statement:

SQL
SELECT CONVERT(DATETIME, '11:22:33')


It's not optimal, because the date part is not used, but still takes up storage space. But then again, downgrading a database to a previous version never is optimal.
 
Share this answer
 
Comments
Lakshmimsridhar 21-Dec-12 2:03am    
hello MR Snehasish hope u remember me. thanks for ur solution
For SQL 2005, I think you need to use DateTime data-type only. Then you can use convert as
SQL
Convert(varchar(10),YourDateTime,108)


In SQL 2008, you have a data-type called "Time" you can use that

Check,

http://msdn.microsoft.com/en-us/library/bb677243.aspx[^]

Milind
 
Share this answer
 
Comments
Lakshmimsridhar 14-Dec-12 0:53am    
i want in sqlserver 2005
MT_ 14-Dec-12 0:54am    
Thats what I said, Its not possible to declare as Time datatype in SQL 2005.
time datatype is not available in SQL SERVER 2005

it is available in SQL SERVER 2008


in SQL SERVER 2005 Datetime datatype is available.

Happy Coding!
:)
 
Share this answer
 
v2

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