• Status: Solved
• Priority: Medium
• Security: Public
• Views: 263

# converting time field to integer

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
Diehl
• 5
• 2
• 2
• +1
1 Solution

Commented:
Hour(Now)
Minute(Now)
0

Commented:
The Hour is in 24-hour time.
0

Commented:
Whole thing:

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

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

Commented:
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 Commented:
what is the 'now'
is that current time?
How do I read the hour and min from the database?
0

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

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

Commented:
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

Senior DBACommented:
You can use the code from above with your field:

SecondsSinceMidnight = (Hour(rs.MyTime) * 3600) + (Minute(rs.MyTime) * 60) + seconds(rs.MyTime)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.