Solved

converting time field to integer

Posted on 2000-05-12
10
245 Views
Last Modified: 2010-05-02
I am taking a field from Access (short time format) and I need to convert it to an integer (number of seconds past midnight)
I understand the idea of getting the hour, mutiplying it by number of seconds in an hour and then adding that to number of seconds in the minutes.

But how do I get that hour value and that minute value

0
Comment
Question by:Diehl
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805932
Hour(Now)
Minute(Now)
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805936
The Hour is in 24-hour time.
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805942
Whole thing:

SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + seconds(Now)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805948
SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + Second(Now)
0
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2805954
Note that if you want seconds, as shown above, there are 86,400 seconds in a day, so you won't be able to store that in an integer (will require a long).
0
 

Author Comment

by:Diehl
ID: 2805955
what is the 'now'
is that current time?
How do I read the hour and min from the database?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2805968
how are you reading the field in?  does it display in military time or AM:PM time?
0
 

Author Comment

by:Diehl
ID: 2805981
The access database is formated in short time:
1:45
14:52
3:15
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 2805989
in that case then you just need to parse the string

Dim hour As String
Dim minute As String
Dim pos As Long

pos = Instr(1,"field",":")
hour = Left("field",pos - 1)
minute = Right("field", 2)
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2806049
You can use the code from above with your field:

SecondsSinceMidnight = (Hour(rs.MyTime) * 3600) + (Minute(rs.MyTime) * 60) + seconds(rs.MyTime)
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question