Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-13
2
Medium Priority
?
388 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:searchsanjaysharma
2 Comments
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 2000 total points
ID: 35122247
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
 

Author Closing Comment

by:searchsanjaysharma
ID: 35122721
ok
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question