• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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

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
MiamiDolphins
Asked:
MiamiDolphins
  • 5
  • 3
1 Solution
 
pcelbaCommented:
convert(varchar(12), dateadd(ms, PreciseLapTime*1000, 0) ,14) as Test2 ,

0
 
pcelbaCommented:
SQL Server 2008 allows even higher time precision (microseconds) using the time data type.
0
 
MiamiDolphinsAuthor Commented:
Hi pcelba when i tried your code
it rounds down to

1:31.053?

why is that
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
pcelbaCommented:
Yes, the accuracy of datetime is restricted, so each result is rounded to increments of .000, .003, or .007 seconds
0
 
MiamiDolphinsAuthor Commented:
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
 
pcelbaCommented:
It is just a cosmetics :-)

select STUFF(SUBSTRING(convert(varchar(12), dateadd(ms, PreciseLapTime*1000, 0) ,14),4, 9), 6, 1, '.')
0
 
MiamiDolphinsAuthor Commented:
Fantastic - Thank you
0
 
pcelbaCommented:
You are welcome. The only disadvamtage of above solution is its restriction to 3599 seconds. Hours are stripped out.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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