473,386 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using TimeSpan or Elapsed e.t.c. Methods

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
Nov 18 '05 #1
5 1183
Hi Kenneth

Have a look at the DateTime.Subtract method :-)

hth, Philipp
Nov 18 '05 #2
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

"Philipp Sumi" wrote:
Hi Kenneth

Have a look at the DateTime.Subtract method :-)

hth, Philipp

Nov 18 '05 #3
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

"Philipp Sumi" wrote:
Hi Kenneth

Have a look at the DateTime.Subtract method :-)

hth, Philipp

Nov 18 '05 #4
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
Nov 18 '05 #5
Hi Philipp,

It just works great.

Thanks a lot.

Kenneth P

"Philipp Sumi" wrote:
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

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: charliewest | last post by:
Can someone pls point me to or recommend the easiest way to calculate someone´s age using the TimeSpan object, in .NET CF? Isn´t there a simple way to use the TimeSpan object to calculate the...
18
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep...
4
by: Rich | last post by:
Hello, I am trying to measure the elapsed time between 2 processes. If I declare startTime As Double, endTime as Double and say startTime = Timer .... process1 ....
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
5
by: Ben | last post by:
Hi I have to run a process in an VB ASP .net. I have to measure how long the process has taken in seconds/miliseconds. Seeing as the Date datatype does not handle miliseconds it seems...
3
by: Horselover Fat | last post by:
Hi, I have a column in a database that holds elapsed time in milliseconds and I want to display that column in a DataGrid in a specific format (d.hh:mm:ss.fff). However, the closest I can get...
3
by: Jeff Jarrell | last post by:
I am unable to add up two timespans as created by the System.Diagnostics.Stopwatch class. Each stopwatch should be about two seconds and is appears ok, but when I try and add them up it goes to...
7
by: hatch | last post by:
The project I am working on has to have start and stop buttons on a form and a label to show the eslaped time once the start button is pushed. The elapsed tome should stop when the stop button is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.