Time Traveller

  • Thread starter Thread starter Merlin
  • Start date Start date
M

Merlin

Does anyone have an example on working with time in VB.

I want to find the quantity of hours and the fraction of an hour between 2
times (e.g. 10.45 - 09.30 = 1.25) - I could do all this by maths, but is
there an inbuilt function to do this. VB help wasn't much use and a search
of the net was much help either.

Thanks for any help.
 
Merlin said:
Does anyone have an example on working with time in VB.

I want to find the quantity of hours and the fraction of an hour
between 2 times (e.g. 10.45 - 09.30 = 1.25) - I could do all this by
maths, but is there an inbuilt function to do this. VB help wasn't
much use and a search of the net was much help either.

The DateTime and Timespan structures should support all you need.
 
Hi,

Look at the timespan class.
Dim ts As TimeSpan

ts = DateTime.op_Subtraction("14:08", "12:12")

Me.Text = ts.ToString

Ken
 
Great!

Just what I was looking for, now to ask another little niggling problem I
have - how do I format a number in vb.net, in VB6 I could use
format$(myvar,"0.000") to format a number to 3 decimal places - how do I do
the same in VB NET (sorry to ask these silly questions, but I've foumd with
VB Net that I'd be flying along coding my program, then pow! I suddenly find
functions that I used all the time in VB6 are suddenly changed and with no
straight forward explanation in the help).

Many thanks Ken.
 
Merlin said:
Great!

Just what I was looking for, now to ask another little niggling
problem I have - how do I format a number in vb.net, in VB6 I could
use format$(myvar,"0.000") to format a number to 3 decimal places -
how do I do the same in VB NET (sorry to ask these silly questions,
but I've foumd with VB Net that I'd be flying along coding my
program, then pow! I suddenly find functions that I used all the time
in VB6 are suddenly changed and with no straight forward explanation
in the help).

When you create a new project, the Format function is still there. Apart
from this, have a look at the ToString method of the object.
 
Back
Top