I want to select and save the entry and exit process according to the time coming from the personnel card reader.
How can I get difference between 2 dates?
- Shift start: 07:00 end: 16:00
- Shift start: 16:00 end: 23:00
- Shift start: 23:00 end: 07:00
string entrystring = "23:00";
string exitstring = "07:00";
string deviceclockstring = "09:00";
TimeSpan entry = TimeSpan.Parse(entrystring);
TimeSpan exit = TimeSpan.Parse(exitstring);
TimeSpan deviceclock = TimeSpan.Parse(deviceclockstring);
double entryTimeDiff = (deviceclock - entry).TotalSeconds;
double exitTimeDiff = (exit - deviceclock).TotalSeconds;
if (entryTimeDiff < exitTimeDiff)
Console.WriteLine("closer to check-in time");
else if (entryTimeDiff == exitTimeDiff)
Console.WriteLine("midway between check-in and check-out");
else
Console.WriteLine("closer to departure time");