Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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