DateTime difference using TimeSpan

G

Guest

I want to use TimeSpan to determine the differences between two date to
include time. My input data is in the following format:

12/25/2004 12:23:00 AM or 01/05/2005 11:59:00 PM

How do I get TimeSpan to accept my input?

How do I get the difference between two dates using TimeSpan?

I want to have the results expressed in days, hours, minutes and seconds.
 
L

Lucas Tam

How do I get TimeSpan to accept my input?

How do I get the difference between two dates using TimeSpan?

You might need to Cdate your string date/times to be accepted as a valid
time format.

You can use DateDiff to get the difference betwen two dates. The results
will be returned as a TimeInterval which has several properties to get the
minutes, hours, days.
 
D

Dennis Powell

Try it this way:
' Create two valid dates
Dim dLast As Date = CDate([strDate])
Dim dNow As Date = Now

Dim iTime As TimeSpan = dNow.Subtract(dLast)

iTime.Minutes returns the minutes of the TimeSpan object.

Hope this helps,
Dennis
 
G

Guest

This what I've been looking for and trying to do.

Thanks



Dennis Powell said:
Try it this way:
' Create two valid dates
Dim dLast As Date = CDate([strDate])
Dim dNow As Date = Now

Dim iTime As TimeSpan = dNow.Subtract(dLast)

iTime.Minutes returns the minutes of the TimeSpan object.

Hope this helps,
Dennis


Larry Bird said:
I want to use TimeSpan to determine the differences between two date to
include time. My input data is in the following format:

12/25/2004 12:23:00 AM or 01/05/2005 11:59:00 PM

How do I get TimeSpan to accept my input?

How do I get the difference between two dates using TimeSpan?

I want to have the results expressed in days, hours, minutes and seconds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

TimeSpan 3
Another C# TimeSpan Question 2
Testing Time Values 8
Add Times? 6
dateTime Manupulations 26
difference between two dates in Month 5
I need to filter on a TimeSpan column 3
Date Calculation 2

Top