473,385 Members | 1,661 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,385 software developers and data experts.

Total number of seconds

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
2 1917

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2...
3
by: Tim | last post by:
I need to get the number of seconds when subtracting two date/times. With the code I am using below I subtract the two date/times and end up with a total of days like "1.56". Then when I multiply...
2
by: Graham | last post by:
I have a variable which can be in the format "mm:ss" or "hh:mm:ss". I would like to extract the total number of seconds from this. Ie "01:30" would be 90 seconds. Thanks in advance !
2
by: msnews | last post by:
Hi All, We have a requirement to display total number of current users using the site. We want to display only the total no other information. And this value needs to change dynamically. Is it...
2
by: Rene Ren | last post by:
I can using Environment.TickCount property to get the time elapsed since the system started. but this property using A 32-bit signed integer type, so it's can't count the time more than 24.9 days....
2
by: tbone | last post by:
In trying to improve the throughput of a classic ASP app I wrote last year, I added monitoring to the application and session start and end methods. For one, I'm counting the total number of...
5
by: simondsm | last post by:
I have a video tape library that we use at work here in a MS-Access database. When originally desgined, we never thought ot convert the time on the fly into total seconds, but instead, we stored...
3
by: Beowulf | last post by:
I have data coming from a telephony system that keeps track of when an employee makes a phone call to conduct a survey and which project number is being billed for the time the employee spends on...
2
by: Paul Furman | last post by:
I don't know, maybe this isn't strange but someone else set up the shopping card coding I'm working with, the way it works is to get the time() in seconds like 1172693735 and that's the shopper_ID...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.