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
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:[^],[^],[^],[^].

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:[^],[^].

This is all you need.

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

Solution 2

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