By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

Total number of seconds

P: n/a
Hi.

My application reads a table that stores data as time, eg: 02:17:31

I need to read this value and convert it to an integer, representing the
total number of seconds. At this moment I am using code like this:
CInt(CDate(drTime(2)).Hour / 3600) + CInt(CDate(drTime(2)).Minute * 60)
+ CInt(CDate(drTime(2)).Second)

Is it the only way to get the total number of seconds? I tried the
TimeSpan object and the TotalSeconds property, but the values I received
were not correct.

Regards,
Chris Leffer

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Chris Leffer" <ch****@wank.com> wrote in message
news:OU**************@TK2MSFTNGP10.phx.gbl...
Hi.

My application reads a table that stores data as time, eg: 02:17:31

I need to read this value and convert it to an integer, representing the
total number of seconds. At this moment I am using code like this:
CInt(CDate(drTime(2)).Hour / 3600) + CInt(CDate(drTime(2)).Minute * 60)
+ CInt(CDate(drTime(2)).Second)

Is it the only way to get the total number of seconds? I tried the
TimeSpan object and the TotalSeconds property, but the values I received
were not correct.


dim d as DateTime ...
dim seconds as integer = cint(d.TimeOfDay.TotalSeconds)

David
Nov 21 '05 #2

P: n/a
Chirs,

Shouldn't you be multiplying the hour times 3600, not dividing by 3600?

Here is some code that uses Timespan and gets the same result as manually
calculating from the components of datetime:

Dim myDT As New DateTime
myDT = Now
MsgBox(myDT)

Dim myTS As New TimeSpan(myDT.Hour, myDT.Minute, myDT.Second)
MsgBox(myTS.TotalSeconds)

MsgBox(myDT.Hour * 3600 + myDT.Minute * 60 + myDT.Second)

Kerry Moorman

"Chris Leffer" wrote:
Hi.

My application reads a table that stores data as time, eg: 02:17:31

I need to read this value and convert it to an integer, representing the
total number of seconds. At this moment I am using code like this:
CInt(CDate(drTime(2)).Hour / 3600) + CInt(CDate(drTime(2)).Minute * 60)
+ CInt(CDate(drTime(2)).Second)

Is it the only way to get the total number of seconds? I tried the
TimeSpan object and the TotalSeconds property, but the values I received
were not correct.

Regards,
Chris Leffer

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.