I am trying to get the timespan of 2 date and time, but i want it to be in only the value of counting the hours before converting to double...
static void Main() {
string tin = "Nov 08, 2021 4:23 PM";
string tout = "Nov 10, 2021 4:23 AM";
DateTime t1 = DateTime.Parse(tin);
DateTime t2 = DateTime.Parse(tout);
TimeSpan Workingtime = t2 - t1;
string time = Workingtime.ToString();
string[] timesplit = time.Split(':');
double num = double.Parse(timesplit[0]) (double.Parse(timesplit[1]) / 60);
Console.Write(num);
}
CodePudding user response:
I think you're looking for something like this:
//Example returns 24 hours
var d2 = DateTime.Now.AddDays(-1);
var d1 = DateTime.Now;
var dif = d1.Subtract(d2).TotalHours; //Returns difference in hours