Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir,
I have to pass Show Time not date in Database in sql I m using smalldatetime datatype for a field name startTime present in my project well in database it is saving like this. 1/1/1900 09:30:00 how to remove this thing 1/1/1900 only database should save 09:30:00 should I use datediff for this Give one Hint please.

[Edited]Minor Formating[/Edited]
Posted
Updated 10-Nov-11 19:35pm
v2

Use only time part by converting convert(varchar,getdate(),108)
this will only store the time portion of your datetime string
 
Share this answer
 
v2
Comments
RaviRanjanKr 11-Nov-11 1:34am    
[Edited]Minor formating of your Answer[/Edited]
use DateTime data type and format time as follows

string dt = String.Format("{0:HH:MM:SS}", txtDate.Text);
 
Share this answer
 
v2
In sql why dont you take simply varchar type and
check the following example to save only time, it may help you :
C#
DateTime dt = DateTime.Now;
        string srt= String.Format("{0:T}", dt);

this return time only from datetime as: 11:53:08 am
for more refer:http://www.csharp-examples.net/string-format-datetime/[^]
 
Share this answer
 
v3
There is no native way to save only the time component in an SQL database. You will have to save it with the date, and then when you retrieve it you can use the T-SQl time[^] keyword.

Hope this helps
 
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