Get the hours difference in time

Hi, I have two string such as 12/30/1899 08:30:00
image

I need to find the hour differences between those 2 variable(both are generic value).

Any suggestions?
I tried few but didn’t work for me.

Thank you xoxo

Hi @sangasangasanga,

TimeSpan diff = DateTime.Now - DateTime.Now.AddDays(-1);
double hours = diff.TotalHours;

Regards,
Arivu

Hi @arivu96, could you pls elaborate?
var2:12/30/1899 18:00:00
var1: 12/30/1899 08:30:100
When I minus, I should get 8.5 hours as diff

test.xaml (7.7 KB)

Check the following sequence.

Hi @sangasangasanga,
use below code
(DateTime.ParseExact("12/30/1899 18:00:00", "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)-DateTime.ParseExact("12/30/1899 08:30:00", "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)).TotalHours.ToString()

Regards,
Arivu

6 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.