what i need to do, is have two defined strings that is inputted by the user,
string in = "9:35"; //am
string out = "11:55"; //am
and i need to subtract them, so that would get the total hours that they were signed in. which should equal:
string total = "2:20"
then, i need to convert that into a decimal.. so, 2:20 would be
string decimal = "2.33";
I dont know how to do that, any help would be appreciated!
P.S: id also like to be able to calculate the total hours they were checked in from a decimal number, so basically the opposite
You need h->segundos = segundos % 60; in the function.
The easiest way to convert time to decimal in Excel is to multiply the original time value by the number of hours, seconds or minutes in a day: To convert time to a number of hours, multiply the time by 24, which is the number of hours in a day.
DateTime dt1 = DateTime.Parse("11:55");
DateTime dt2 = DateTime.Parse("9:35");
double span = (dt1 - dt2).TotalHours;
Do you actually need the "2:20" or is that just an intermediate step?
Edit: If you wanted to go back, you'd just need to do a little bit of math. Take the remainder of the decimal and multiply by 60, then round. Those will be the minutes, so just add them to the hours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With