Solved

# How to i Convert a Float to a Time (with Milliseconds)

Posted on 2009-04-25
204 Views
Hi Guys/Gals

i've got a value - currentlys stored as a float

the figure is

91.0546035766602

I would like to convert this to

1:31:054

i did get this code below

but this only converts to

1:31:000

convert(varchar(12), dateadd(second, PreciseLapTime, 0) ,14) as Test2 ,

0
Question by:MiamiDolphins

LVL 41

Expert Comment

convert(varchar(12), dateadd(ms, PreciseLapTime*1000, 0) ,14) as Test2 ,

0

LVL 41

Expert Comment

SQL Server 2008 allows even higher time precision (microseconds) using the time data type.
0

Author Comment

Hi pcelba when i tried your code
it rounds down to

1:31.053?

why is that
0

LVL 41

Expert Comment

Yes, the accuracy of datetime is restricted, so each result is rounded to increments of .000, .003, or .007 seconds
0

Author Comment

ok and finally

could u modify the code slighty so that i can

1:31:053

i.e no 0s at the start for hours

currently getting

00:01:31.053

but would actually like

say
01:31.053

0

LVL 41

Accepted Solution

It is just a cosmetics :-)

select STUFF(SUBSTRING(convert(varchar(12), dateadd(ms, PreciseLapTime*1000, 0) ,14),4, 9), 6, 1, '.')
0

Author Closing Comment

Fantastic - Thank you
0

LVL 41

Expert Comment

You are welcome. The only disadvamtage of above solution is its restriction to 3599 seconds. Hours are stripped out.
0

## Featured Post

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.