4
Answers

Date time pickers

durga prasad

durga prasad

16y
4.1k
1
Hi,
I have a problem in a project , in this project I used intime and outtime as two fields(Datetime pickers), on outtime textchanged event it had to calcualte outtime - intime - 30min(Lunchtime) and display it in a text box.In case if the employee works more than 8:30 hours .For example 12 hours than it has to calculate like Extra hours = Total hours worked  - (min hours  woked +lunch hours) eg., extrahours  12 - (8:30+30) -> 12 - 9 -> 3 hours , then in another text box it has to display 3 hours as extra hours worked.
I used double and time spans buts its not working out, please help me out.
String tot = String.Empty;
            TimeSpan ts = new TimeSpan();
            ts = dtpouttime.Value.TimeOfDay - dtpintime.Value.TimeOfDay;
            txtworkedhours.Text = ts.ToString();
            txtworkedhours.Text = Convert.ToDouble(Convert.ToDouble(ts.Hours - 0.50) + (Convert.ToDouble(ts.Minutes) / 60.00)).ToString("#.00");

Thanks in Advance,
Prasad
Answers (4)