string to time

hair

Registered User.
Local time
Today, 15:22
Joined
Mar 27, 2003
Messages
125
I have no choice, as I didn't find the answer searching the forum. I need to transform a time like 32:30 (actually is a string) in a usable format, like 1,76etcetc so I can put it in calculations. I've tried cdate function and a lot of stuff but didn't work. Should I transform everything in seconds and after in days?

If somebody has already a function who does that it would be great
 
hair,

What does 32:30 mean?

Access has many functions to deal with dates/times. But 32:30
is new to me.

Is it 32 and 1/2 hours?

If it is, with respect to what?

Wayne
 
HI Wayne

32:30 are 32 hours and 30 minutes. I have this in a table as a contract, so the person can have between 18 and 42 hours a week to work. Obviously I had to make it as a string cause there are numbers bigger then 24 hours.

I can't work with a string, so I need, for instance, if it's 36 hours the contract, a function that transform the 36 hours in 1,5 days.
Voila. The reverse function I have it from Mile, named Timeconversion, and it's working just great
 
I think Mile-O-Phil did something much more extensive on the same subject. Maybe if you search on his name.....

But this "Oneliner" will do what you want, mind you no error trapping or nothing....
Code:
Function StringToDateTime(actualTime As String) As Double
    StringToDateTime = (CInt(Left(actualTime, 2)) + CInt(Right(actualTime, 2)) / 60) / 24
End Function

Regards
 
its working and it looks so easy when its somebody else who did it...

Thanks mailman
 
namliam said:
I think Mile-O-Phile did something much more extensive on the same subject. Maybe if you search on his name

Mines added times in a query. Here's the link to a discussion.
 
Oh, but your function is used in my app every 10 seconds :-)
For quite a while actualy, and it goes over 1000 hours which is great

But it gives a string, what I wanted was the opposite, and the Mailman's function does that. But I repeat, Timeconversion is the kernel of all my results for quite a while :-)

Actualy, you provided a simpler version in the beginning(like in may or something), that sometimes was giving bugs(depassing capacity for seconds even though it was a double), and a complete one later that has no bugs
 

Users who are viewing this thread

Back
Top Bottom