446,285 Members | 1,647 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

# extract Integer part of TimeSpan.TotalMinutes?

 P: n/a 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 Nov 21 '05 #1
7 Replies

 P: n/a "Rich" schrieb: 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))'. -- M S Herfried K. Wagner M V P V B Nov 21 '05 #2

 P: n/a Rich, Why you don't use the minutes property? Otherwise I would use the toString to get the double in a string. Cor Nov 21 '05 #3

 P: n/a 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). "Cor Ligthert" wrote: Rich, Why you don't use the minutes property? Otherwise I would use the toString to get the double in a string. Cor Nov 21 '05 #4

 P: n/a 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. "Herfried K. Wagner [MVP]" wrote: "Rich" schrieb: 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))'. -- M S Herfried K. Wagner M V P V B Nov 21 '05 #5

 P: n/a 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 Nov 21 '05 #6

 P: n/a "Cor Ligthert" schrieb: 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 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. -- M S Herfried K. Wagner M V P V B Nov 21 '05 #7

 P: n/a 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 Nov 21 '05 #8

### This discussion thread is closed

Replies have been disabled for this discussion.