Sai Yang

Sai Yang

  • NA
  • 136
  • 27.7k

[C#] How to get HH:mm from two datetimes?

Apr 6 2018 11:31 AM
hi there,
 
how to get Duration of log in and log out system in the format of HH:mm from two datetime?
 
I using this code:
 
DateTime now = DateTime.Now;
TimeSpan hrs = now - timein;
double z = hrs.TotalHours;
 
if using system for two hours
 
z = 2.700123 something like that. 
 
 it doesn't support my needed.
 
what I want is like: 
e.g
 
logintime                              logouttime                          duration 
06/04/2018 23:04:36           07/04/2018 23:05:08          HH:mm      or (e.g)  z=24:30 
  
format dd/MM/yyyy HH:mm:ss .
 
Mean 24 hrs and 30 minutes; after 30 minutes z=25:00 hrs. (not 24.5004343534). 
 
 Duration should be more than 24 hour upto days log in if using two days will display like 48:30........
 
 
How can I display that????
 
 
Best regard; 
 

Answers (5)