3
I am asking this question because I have not located any topic with my problem, which is very similar to others.
I have 2 fields TimeSpan?
one of which relates to check-in time and the other to departure time.
I want to know the time difference, so if the person works from 8:00 to 10:00, he worked 2 hours.
This is very simple, maybe with a Compare or a sub I can extract this total value, but when I inform that the person entered at 17:00 and left at 16:00 he returns me 1, being that he worked 23 hours
How can I make that calculation?
if he worked from 16(4 hours) and left at 17(5 hours), he will return one hour even if you are trying to say that he went in one day and went out the other you also have to compare the day.
– Vinicius
I got confused in the text, if he entered at 17 and left at 16 o'clock, already corrected in the text.
– Voltz
"when I inform that the person entered at 16:00 and left at 17:00 he returns me 1, being that he worked 23 hours" so I understood this is right, he should return 23 if the person enters at 17 and leaves at 16, no?
– rLinhares
@Exactly, that’s what I’m having trouble with, knowing from 17 to 16 hrs
– Voltz
http://stackoverflow.com/a/4946393/4551469 sees if this way works
var hours = (datevalue1 - datevalue2).TotalHours;
– rLinhares
Theoretically the values will never be fixed so she can report that is input 15hrs and exit at 18hrs, how much can also be from 18hrs until 17hrs the other day. I would have to make a check if the date left was less than the date of entry and add 1 day on the date left, it would be this ?
– Voltz
There is confusion there. You need as a response a period, a time interval, then the answer will be a
TimeSpan
. Data entry is the time of entry and time of exit, so they are two points in time, IE, should beDateTime
. When it starts wrong it’s hard to make it right.– Maniero
I figured it out, you were right, all I had to do was convert to
DateTime
and add 1 day to the check-out date when it is less than the check-in date.– Voltz
And I used the Totalhours @rLinhares reported. Thank you very much!
– Voltz