Click here to Skip to main content
15,883,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,
I have two drpdown list box. dropdown1 is for start time and dropdown2 is for end time.
suppoce in dropdown1 select 8:00AM and Dropdown2 select 08:30 AM how we calculate time and store in database.
Thankyou in Advanced
Posted
Comments
Patrice T 2-Dec-15 3:54am    
What have done so far ? Where are you stuck ?

This is not very advanced.

1. Get the selected values from each dropdown box.

2. If the values are strings, you need to convert them to the data type DateTime, see DateTime.TryParse[^]

3. Then you subtract the two DateTime variables.
The result will be an object of type TimeSpan[^].

4. Store the value in a suitable table in your database
See SQL Insert[^]

5. You will also need a database connection[^] and a SQL command[^]

That should do it, I think.
 
Share this answer
 
v2
1. Get the time difference like this-
C#
TimeSpan time1 = TimeSpan.Parse(dropdown1.SelectedItem); // can't recall the actual property to get the selected item text :laugh:
TimeSpan time2 = TimeSpan.Parse(dropdown2.SelectedItem);
TimeSpan difference = time1 - time2;
int hours = difference.Hours;
int minutes = difference.Minutes;


2. Use the SQL Insert[^] statement to store the appropriate value in database. Refer this tutorial[^] for more idea.


-KR
 
Share this answer
 
v2
Comments
George Jonsson 2-Dec-15 4:13am    
Don't you mean
DateTime time1 = DateTime.Parse(dropdown1.SelectedItem);
?
George Jonsson 2-Dec-15 17:58pm    
But 8:30PM is not an interval. Right?

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