Solved

# converting time field to integer

Posted on 2000-05-12
252 Views
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
Question by:Diehl
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 2
• 2
• +1

LVL 9

Expert Comment

ID: 2805932
Hour(Now)
Minute(Now)
0

LVL 9

Expert Comment

ID: 2805936
The Hour is in 24-hour time.
0

LVL 9

Expert Comment

ID: 2805942
Whole thing:

SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + seconds(Now)
0

LVL 9

Expert Comment

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

LVL 9

Expert Comment

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

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

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

Author Comment

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

LVL 28

Accepted Solution

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

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

Question has a verified solution.

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

### Suggested Solutions

Enums (shorthand for â€˜enumerationsâ€™) are not often used by programmers but they can be quite valuable when they are. Â What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that containsâ€¦
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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â€¦
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process fromâ€¦
###### Suggested Courses
Course of the Month7 days, 8 hours left to enroll