Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how do i find time diffrence

Posted on 2004-10-25
5
Medium Priority
?
217 Views
Last Modified: 2010-04-24
im trying to find time diffrence between two times... in hours,mins,sec

example
10/24/2004 12:12:47 AM
10/24/2004 12:12:49 AM

in this case its 0 hours, 0 mins, and 2 seconds



the format for the date - time string will stay the same... in each case...

thx
Johnny
aka Pern

0
Comment
Question by:Johnny
[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
5 Comments
 
LVL 14

Expert Comment

by:dfu23
ID: 12400381
Use the DataDiff function ... example:

http://www.experts-exchange.com/Programming/Q_21069414.html

0
 
LVL 6

Expert Comment

by:KGreg
ID: 12400597
Date.Subtract returns a TimeSpan object, from which you can get the total days, seconds, minutes, etc.

Msgbox(Date.Subtract(Now, MyDate).TotalSeconds.ToString)

KGREG
0
 
LVL 4

Expert Comment

by:Glom
ID: 12400614
Hi,

Dim a as Date = #10/24/2004 12:12:47 AM#
Dim b as Date = #10/24/2004 12:12:49 AM#
Dim diff As TimeSpan = b.Subtract(a)

Then you can access to all the TimeSpan properties : for example diff.Seconds() to have the number of second elapsed between a and b.

Glom
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 12401694
I agree with KGreg and Glom but if you are getting the dates as strings then use DateTime.Parse() first to convert them to dates and then proceed to use the .Subtract() function with the TimeSpan() class:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strDateA As String = "10/24/2004 12:12:47 AM"
        Dim strDateB As String = "10/24/2004 12:12:49 AM"

        Dim dateA As DateTime = DateTime.Parse(strDateA)
        Dim dateB As DateTime = DateTime.Parse(strDateB)

        Dim ts As TimeSpan = dateB.Subtract(dateA)

        MsgBox(Format(ts.Hours, "00") & ":" & Format(ts.Minutes, "00") & ":" & Format(ts.Seconds, "00"), MsgBoxStyle.Information, "Difference")
    End Sub

~IM
0
 

Author Comment

by:Johnny
ID: 12402325
Perfect thx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

610 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