Click here to Skip to main content
14,210,491 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have two drop down list one has hour from 7 to 7 and other has minutes of time interval 5minutes.

So What I want is if user selectes

1 from the ddl so while inserting time in the database it should get store as 13:00 instead of 1. like wise i need the timing from 1 to 7 and get stored in to datanase with 13:00, 14:00, 15:00..etc..

I have time datatype in the database for storing the time value .

Please help.

Thank you
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Well, you don't need to convert anything. You want to work with data, not string representation of data. If you are using System.DateTime, such objects do not have "formats". The formats should appear only when you present them on the UI, and no "conversion" is involved. You only use System.DataTime.ToString with appropriate parameters. All you need to do is format specifiers and/or culture you want to use. Please see:
http://msdn.microsoft.com/en-us/library/k494fzbf.aspx[^],
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^],
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx[^].

Reading these help pages, pay attention for the culture-sensitive nature of these methods. And now, the format specifiers. They fall into standard and custom categories:
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

This is all you need.

—SA
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,
Say that the ddl for hours be named DDLH.
Follow the steps below:
1. Store the balue selected in DDLH in a string varioable.
2. In an integer variable convert the string value into intger using Int32.Parse(string) and add 12 to it. You will have the time in 24hrs. format.
3. Insert the value into database.

Here is quick suggestion you might follow for convenience in coding. Try to keep the fields in your database mostly int, string(or text), float, double, and so other convenient data types. You may use a masked textbox or you can use a datetime picker for choosing date. It will be easy both for and the user.

In case I misunderstood your question or you require more clarification do let me know.

Thank You.
   

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



Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190618.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100