Hi i would like to calculate working hours by employee.
I have 3 text boxes txtMorningInTime,txtMorningOutTime,txtMorningTotHrs
I will enter logged in time , logged out time and then i should get the correct working hours. By viewing some links here i tried but its not working. i am using following code suggested by some one here on C# Corner
DateTime loggedIn = Convert.ToDateTime(txtMorningInTime.Text);
DateTime loggedOut = Convert.ToDateTime(txtMorningOutTime.Text);
TimeSpan totHrs = loggedIn - loggedOut;
txtMorningTotalHrs.Text = totHrs.ToString();
But whats happening is ,if i put loggedin time as 10.30(its AM) and logged out time is 2.30 (PM), it should calculate 4 hours.
when i debug its converting the value in txtMorningInTime.text as (30/10/2020) and giving error string was not in correct format for txtMorningOutTime.Text.
what is the solution for this. I need some urgent help. How can i convert the textbox time to time and calculate total working hours.
Thanks In Advance.