Using TimeSpan or Elapsed e.t.c. Methods

G

Guest

Hi,

I'm having a problem to measure the time between two events

Dim StrStart As DateTime = DateTime.Now.ToString("h:mm:ss.fff")
.... do some stuff ...
Dim StrEnd As DateTime = DateTime.Now.ToString("h:mm:ss.fff")
Dim Total As TimeSpan
Total = TmeSpan(StrEnd, StrStart) ' doesn't work
StrTotal = Total.ToString()
lblOut.Text = "Start: " & StrStart & " End: " & StrEnd

Any suggestions to the code or any ideas?

TIA

Kenneth P
 
G

Guest

Hi Philipp,

I did, and when I tried some code there I tried to response.write it and it
went well, but when I wanted to put the result of a timespan with the
Subtract method it says you cannot convert a timespan object into a string
object.

So I'm in a dead end.

Kenneth P
 
G

Guest

Philipp,

Maybe I should give you some code I tried.

Dim starttime As DateTime
Dim endtime As DateTime
starttime = DateTime.Now
Dim diff1 As System.DateTime
.... doing some stuff....
endtime = DateTime.Now '("h:mm:ss.fff") trying with milliseconds, help?
diff1 = EndTime.Subtract(StartTime)
Response.Write(diff1) ' will work
lblTottime.Text = diff1 ' will not work

Any ideas on what to change in code to get the result into a label.text
property?

Kenneth P
 
P

Philipp Sumi

Kenneth,
Any ideas on what to change in code to get the result into a label.text
property?


If you write the TimeSpan, the output will be automatically converted
into a string - that's why it worked. However, assigning the TimeSpan to
the Text property of a Label does not work as the TimeSpan is a TimeSpan
and the property needs to get a string.

If the string output of Response.Write was ok for you, this should do:
lblTottime.Text = diff1.ToString()

Cheers,
Philipp
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top