Thursday, March 22, 2012

measuring time difference

Hi guys

I have a problem with timestamps in VB.NET
I receive 2 strings with the following format: YYYYMMDD

I would like to know the difference between them in days.

For instance: 20040630 (30 June) - 2004073 (3 July) = 3 days

Are there any time functions that calculate this? or which steps do I have to take to achieve this...

Thanks!Hi,

this could be of help to you:DateTime.Subtract Method.

Grz, Kris.
Check this out

<link>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclasssubtracttopic1.asp</link
--
I already found the answer....


Function TimeDifference(ByVal strStart As String, ByVal strFinish As String) As String
Dim strStartNew As String = Left(strStart, 4) & "-" & Mid(strStart, 5, 2) & "-" & Right(strStart, 2)
Dim strFinishNew As String = Left(strFinish, 4) & "-" & Mid(strFinish, 5, 2) & "-" & Right(strFinish, 2)
Return DateDiff(DateInterval.Day, CDate(strStartNew), CDate(strFinishNew))
End Function

But tnx anywayz!

0 comments:

Post a Comment