473,396 Members | 2,052 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,396 software developers and data experts.

extract Integer part of TimeSpan.TotalMinutes?

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 6197
"Rich" <Ri**@discussions.microsoft.com> 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 <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
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
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
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" <Ri**@discussions.microsoft.com> 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 <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
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
"Cor Ligthert" <no************@planet.nl> 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 <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Justin Grieves | last post by:
Hello all, I've been trying to determine the difference in minutes between two DateTime objects (startTime and endTime) in C# using the TimeSpan object (ts). I am populating the two DateTime...
2
by: Philip Townsend | last post by:
I need to determine if a file's last write time is greater than 15 minutes. Is there a simple way to do this with the TimeSpan object? Thanks! *** Sent via Developersdex...
5
by: Larry Bird | last post by:
I want to use TimeSpan to determine the differences between two date to include time. My input data is in the following format: 12/25/2004 12:23:00 AM or 01/05/2005 11:59:00 PM How do I get...
10
by: Charles Law | last post by:
If I display a TimeSpan I get something like 00:05:17.6217891 when what I would like to see is 00:05:18 Is there an easy way to get this output? Try as I might I just can't find it.
5
by: gh | last post by:
I have 2 columns in a grid where the user enters a begining time(TI) and at the end of the day an end time(TO). I then want to take the TO - TI to get the difference and display it as hours and...
2
by: Bob | last post by:
Greetings All, Is there a simple way of suppressing the fractional part of a timespan At the moment I use one time span to populate another minus the fractional part .. this is a bit clunky. ...
5
by: | last post by:
Why is it that: DateTime start = DateTime.Parse("1:00 AM"); DateTime stop = DateTime.Parse("2:30 AM"); TimeSpan ts = stop - start; Response.Write(ts.Minutes.ToString()); Produces 30, not 90?...
3
by: Curious | last post by:
I have code below. But it won't compile. Error: Cannot implicitly convert type 'System.TimeSpan' to 'System.DateTime' DateTime now = DateTime.Now.TimeOfDay; DateTime openTime =...
4
by: Pachalo | last post by:
Morning... Am working on a simple billing system and a looking for a code that can help calculate the difference in time between sessions..(am using VB.Net ) This is what is happening: l...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.