Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting text data type into number 1

Status
Not open for further replies.

srd

Technical User
Oct 16, 2001
14
PT
Hi!

I have a series of time data that are formated into text data type (e.g. 1:00, 7:32 (min:secs)), but I need to analyze it and have to do some operations with it. When I try to change the data type I get some errors...

Is there a way to convert it, without lossing info and at the sametime not time consuming?

Many Thanks in advanced

sIMAO d.
 
I assume you want to convert your text time to a decimal representation of time, i.e. 7:30 will be 7.5.

CDbl(Left([mytime], InStr([mytime], ":") - 1) + (CLng(Mid([mytime], InStr([mytime], ":") + 1)) / 60))

In a query you might do:

select CDbl(Left([mytime], InStr([mytime], ":") - 1) + (CLng(Mid([mytime], InStr([mytime], ":") + 1)) / 60)) as mytime_dec
from mytable

Mike Pastore

Hats off to (Roy) Harper
 
And If instead of 00(mins):00(secs) I would have 00(hours):00(mins):00(secs)?

And yes I would like to change it to a decimal number of minutes (X,xxx mins).

Thank you

sIMAO d.
 
Assuming a properly formatted text (00:00:00):

CDbl(Left([mytime], 2)) + (CDbl(Mid([mytime], 4, 2) / 60)) + (CDbl(Right([mytime], 2) / 3600))

Mike Pastore

Hats off to (Roy) Harper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top