Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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