Solved

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

Posted on 2011-03-13
2
381 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 500 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

785 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