Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-13
2
Medium Priority
?
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 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