Click to See Complete Forum and Search --> : DateTime and TimeSpan Types


Curt
April 30th, 2002, 10:48 AM
I'm using a 3rd party chart COM object (National Instruments CW graph) to plot data versus elapsed time.
The x value needs to be a VB6 equivalent Date type
which is a .NET DateTime datatype.
What I need is a way to convert a TimeSpan datatype to a DateTime datatype.



Dim testTime as System.DateTime 'date
Dim plotTime as System.DateTime 'date
Dim elapsedTime as System.TimeSpan
Dim Val1 as Double = 1
'.........
startTime = Now
'in timer event
testTime = Now
elapsedTime = System.DateTime.op_Subtraction(testTime, startTime)
Val1 = +1
'throws error
CWGraph1.Plots.Item(1).ChartXvsY(elapsedTime, Val1)








Curt

p3tr
October 19th, 2009, 09:27 AM
Hello.

had the same question.
What i found to work:

1) cast both as doubles
2) do math
3) cast back as date

like this:

oDateTo.Value = Now
Dim dTemp As Double
dTemp = iDaysBack
Dim dT1 As Double
dT1 = Now.ToOADate
dT1 = dT1 - dTemp

oDateFrom.Value = Date.FromOADate(dT1)

where i had 2 date pickers (oDateFrom and To), and iDaysBack as date offset back from now.

So now some dweeb is going to say something about "why didn't i use this object" and 'm going to strangle him with my mouse-cable, cos WHY DIDN'T HE POST IT HERE IN THE FIRST PLACE??

regards
p

HanneSThEGreaT
October 20th, 2009, 02:27 AM
This dweeb is saying that this thread is seven years old.

Thanx for sharing though :)