473,501 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Elapsed Time to Seconds

I need to be able to enter an elapsed time into a text
field. This time then needs to be converted into seconds
and stored in a field in some table.

The user will enter a time (format is h:minutes:seconds)
as such:

0:15:34 (0 hours, 15 minutes, 34 seconds -> 934 seconds total)

or as another example:

1:02:10 (1 hour, 2 minutes, 10 seconds -> 3730 seconds total)

Can someone please walk me through this? I imagine this is
VBA related (an Event Procedure), but I'm not sure of the
code or what 'Event' type to out this under for the given
text field.

Thanks.
Nov 12 '05 #1
3 29012
lucky for you, Access has 3 functions to assist your needs, and they
can be used in queries or in VB under forms to calculate a control to
a value that will update the desired table field.

These fuctions are hour(), minute(), and second(). Each one takes a
date/time OR a string time format, i.e. (like your user's will enter):
"03:45:23".

Then, all you need to do is run these three functions on that field to
achieve your result: hour(<dateORtextField>) * 3600 +
minute(<sameField>) * 60 + second(<sameField>).

That's it.
-Paul T.

fr*******@yahoo.com (fred14214) wrote in message news:<90**************************@posting.google. com>...
I need to be able to enter an elapsed time into a text
field. This time then needs to be converted into seconds
and stored in a field in some table.

The user will enter a time (format is h:minutes:seconds)
as such:

0:15:34 (0 hours, 15 minutes, 34 seconds -> 934 seconds total)

or as another example:

1:02:10 (1 hour, 2 minutes, 10 seconds -> 3730 seconds total)

Can someone please walk me through this? I imagine this is
VBA related (an Event Procedure), but I'm not sure of the
code or what 'Event' type to out this under for the given
text field.

Thanks.

Nov 12 '05 #2
SELECT tblTimes.ID, tblTimes.TextTime, CDate([TextTime]) AS TestTime,
DateDiff("s",Int(CDate([TextTime])),CDate([TextTime])) AS TestDiff
FROM tblTimes;

Create a numeric field in your table and set its type to long.

Then create an update query to fix all the values for you.

UPDATE MyTable
SET MyElapsedTimeField =
DateDiff("s",Int(CDate([TextTime])),CDate([TextTime]));

BTW, storing derived values usually isn't a good idea. I would base a
query on another query until I got what I wanted... much more
flexible.
Nov 12 '05 #3
Thank you for your time. I have another question.

I am basing a new query on an existing query. In the existing query is a
field of seconds. In the new query, I would like to get the average of
the 'field of seconds' from the old query. I can accomplish this by
using the Group By -> Avg function. This works, but it gives the answers
in seconds. How can I get the new query to display (in the query itself,
not a form) hours:minutes:seconds?

Thank you again.

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12315
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...
6
24787
by: Thomas Bartkus | last post by:
MySQL Version 4.0.20 on a Linux server. How does one get the elapsed time between (2) DateTime values? I need the answer to the nearest minute. Is upgrading to Ver 5 with its more robust...
20
12567
by: Jean Johnson | last post by:
Hello - I have a start and end time that is written using the following: time.strftime("%b %d %Y %H:%M:%S") How do I calculate the elapsed time? JJ
0
1797
by: Anurag | last post by:
Hi, ENV: DB2 ESE 8.2.3 DPF (11 nodes) on AIX 5.x ==== SCENARIO / SETUP ======== ====== (1) I needed to find out CPU Time (User / System) of SQL queries for benchmark testing. (2) I setup...
3
10255
by: Bill Nguyen | last post by:
I need to display elapsed time for a process in VB.NET in secods. What's the routine to do this? Thanks Bill
1
5231
by: Bill | last post by:
I have a large number of records that have an elapsed time in seconds for each one that I was to have a total time spent. I can sum them up with query easily enough but I need to be able to display...
12
16270
by: Spitfire | last post by:
I've a requirement to find the elapsed time between two function calls. I need to find the time elapsed accurate to 1 millisecond. The problem I'm facing right now is that, I'm using the 'time()'...
0
1478
by: Gabriel Genellina | last post by:
En Fri, 02 May 2008 16:13:41 -0300, Simon Pickles <sipickles@googlemail.comescribió: Two options: a) You can construct a datetime object with that info, using...
4
15279
yarbrough40
by: yarbrough40 | last post by:
Can anyone help me to display a Decimal (or double) to elapsed time :mm:ss (hours:minutes:seconds)using vb.net? example: if you were to type "1.34666666666667" into a cell in Excel then choose...
0
7159
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
7226
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
7255
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7419
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5515
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4953
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...
0
4625
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
326
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.