Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello sir...i want to add time like 00:15 ..my database field is datetime....i have use maskedtextbox to insert time..but it show me error bcz in database datatype is datetime....so any solution for this...i want insert only time to the databse not date..plz help me.......
Posted

Hi,

If your server is 2008 SQL server or higher then you can use time [^]

else

Set your field as varchar and put the value in it.

or else

you can set your filed as date time and always add min date value with the time but it will occupy more space than varchar.

:)
 
Share this answer
 
Comments
Mrugesh08 31-Dec-12 0:28am    
i m using sql server 2008....i have used varchar but it look like this...0015...no sepration between them......
Suvabrata Roy 31-Dec-12 0:29am    
then proper way is to use Time, if want to perform additional operation on that data, otherwise use varchar
Mrugesh08 31-Dec-12 0:33am    
ya but time datatype not in sql server 2008...so what can i do..i want to store time in the database...but sql has no time datatype..so when i use datetime and whn i store time show me error that date is require...so what is the Wright way to do this....plz tell me sir....
in sql server 2005 only Time datatype is not available
so, it will save datetime

when you are going to save add date like this
C#
string dttm = "1900-01-01 " + MaskEditbox1.text;

in query...
C#
Query = insert into tbl(dttm) value(" + dttm + ")";


Happy Coding!
:)
 
Share this answer
 
Comments
Mrugesh08 31-Dec-12 0:40am    
Yes....it store static date....
Aarti Meswania 31-Dec-12 0:45am    
hmm it will take default date
Mrugesh08 31-Dec-12 0:47am    
ok mam...i will try this ...thank you mam...happy new year.....
Aarti Meswania 31-Dec-12 0:49am    
welcome! :)
Glad to help you! :)
happy new year dear!
:)
Mrugesh08 31-Dec-12 0:50am    
ok mam..thnx a lot...n you to mam..enjoy...:)

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