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

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
Asked:
Diehl
  • 5
  • 2
  • 2
  • +1
1 Solution
 
GivenRandyCommented:
Hour(Now)
Minute(Now)
0
 
GivenRandyCommented:
The Hour is in 24-hour time.
0
 
GivenRandyCommented:
Whole thing:

SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + seconds(Now)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
GivenRandyCommented:
SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + Second(Now)
0
 
GivenRandyCommented:
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
 
DiehlAuthor Commented:
what is the 'now'
is that current time?
How do I read the hour and min from the database?
0
 
AzraSoundCommented:
how are you reading the field in?  does it display in military time or AM:PM time?
0
 
DiehlAuthor Commented:
The access database is formated in short time:
1:45
14:52
3:15
0
 
AzraSoundCommented:
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
 
Brendt HessSenior 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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 5
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now