Link to home
Start Free TrialLog in
Avatar of Diehl
Diehl

asked on

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

Avatar of GivenRandy
GivenRandy

Hour(Now)
Minute(Now)
The Hour is in 24-hour time.
Whole thing:

SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + seconds(Now)
SecondsSinceMidnight = (Hour(Now) * 3600) + (Minute(Now) * 60) + Second(Now)
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).
Avatar of Diehl

ASKER

what is the 'now'
is that current time?
How do I read the hour and min from the database?
how are you reading the field in?  does it display in military time or AM:PM time?
Avatar of Diehl

ASKER

The access database is formated in short time:
1:45
14:52
3:15
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Brendt Hess
You can use the code from above with your field:

SecondsSinceMidnight = (Hour(rs.MyTime) * 3600) + (Minute(rs.MyTime) * 60) + seconds(rs.MyTime)