extract Integer part of TimeSpan.TotalMinutes?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dim tse As TimeSpan, sTime, eTime As Date, m As Double
sTime = Now
.....stuff
eTime = Now
tse = eTime.Subract(sTime)
m = tse.TotalMinutes

'--get Int portion of m
Console.WriteLine(Ctype(m, Integer))

Is this the correct/best way to do this?

Thanks,
Rich
 
Rich said:
Dim tse As TimeSpan, sTime, eTime As Date, m As Double
sTime = Now
....stuff
eTime = Now
tse = eTime.Subract(sTime)
m = tse.TotalMinutes

'--get Int portion of m
Console.WriteLine(Ctype(m, Integer))

Is this the correct/best way to do this?

If you don't want rounding to take place, you may want to use something like
'CInt(Int(m))'.
 
Rich,

Why you don't use the minutes property?

Otherwise I would use the toString to get the double in a string.

Cor
 
Yes, of course. Instead of taking a double like Dim m As Double

m = tse.TotalMinutes

I could use Herfried's suggestion

Dim m As Integer
m = Cint(tse.TotalMinutes)

I was getting confused with VB.Net's complaint about using an Int with a
Double. I guess the trick is to cast with Cint (or Int).
 
Thanks for your reply. I am thinking

Dim m As Integer
m = Cint(tse.TotalMinutes)

I was getting confused on the casting thinking that you always have to use
CType.
 
Rich,
I could use Herfried's suggestion

Dim m As Integer
m = Cint(tse.TotalMinutes)
In my opinion is that the same as using the minutes property.

m = tse.Minutes

Cor
 
Cor Ligthert said:
In my opinion is that the same as using the minutes property.

m = tse.Minutes

No, that's something different. 'TotalMinutes' will return the whole
timespan's value in minutes, 'Minutes' will return the minutes which are not
"covered" by full hours.
 
Herfried,
No, that's something different. 'TotalMinutes' will return the whole
timespan's value in minutes, 'Minutes' will return the minutes which are
not "covered" by full hours.

You are right, wrong thinking from me.

:-)

Thanks for attending me on this.

Cor
 

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

Back
Top