How to find no. of hours between 2 dates in asp.net

I have 2 dates d1 and d2.
in dd mm yyyy hh mm ss format.
How to find the no. of hours between 2 dates.
searchsanjaysharmaAsked:
Who is Participating?
 
Ajay SharmaConnect With a Mentor Commented:
Use TimeSpan

DateTime dt1 = new DateTime();
        dt1 = DateTime.Now.AddDays(-2);

        DateTime dt2 = new DateTime();
        dt2 = DateTime.Now;

        TimeSpan timeDiff = dt2 - dt1;
        lblMessage.Text = timeDiff.TotalHours.ToString()
0
 
searchsanjaysharmaAuthor Commented:
ok
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.