Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

I have 3 dropdownlist as in a label
They are:
1.) Hours HH
2.) Minutes MM
3.) Am/pm

So how do i store them into database and retrieve them from the database.
Please help me out.
Posted

Well, You can combine all three values in hh:mm tt format and then cast it to Time or TimeSpan or DateTime.

This is code give you an Idea...

TimeSpan ts = new TimeSpan(05,55,00);
DateTime t = DateTime.Today.Add(ts);
string dsTime = date.ToString("hh:mm tt");


In database you will be needed a Time or string DataType for your field.

Also go through following link which will help you further in Date/Time conversion.

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^]
 
Share this answer
 
Convert them to a Time or DateTime object and store them in that format. You could also make use of Time Picker Ajax Extender Control[^].
 
Share this answer
 
Hi use following syntax for saving time value to database.

At database side :

SQL
CREATE TABLE Table1 ( Column1 time(7) )


And at code side :

C#
string time=ddlHour.selectedvalue+":"+ddlMinutes.selectedvalue+":00" + ddlAMPM.selectedvalue;

// insert into table1(Column1) values ('"+time+"')


you should pass above query as command in sql server.
 
Share this answer
 
Comments
Richard MacCutchan 31-Dec-13 7:58am    
That is a very bad idea. You should never store times or dates as strings.
BK 4 code 31-Dec-13 23:20pm    
take a look table defination , i think you should read whole answer again

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