Solved

Convert Numeric field to Time

Posted on 2011-09-26
8
293 Views
Last Modified: 2012-06-27
I have a numeric field starttime_t numeric(5,2) which stores decimal time in quarter hours. example 8.15, 8.30,8.45, 9.00 what I need to do is report this as time. example 08:15:00

8.15pm should be 20:15:00 any help will be appriciated

0
Comment
Question by:mguptill
8 Comments
 
LVL 13

Expert Comment

by:Wizilling
ID: 36601876
hi - if its a numeric field then you wont be able to store pm.
can you confirm that 8:15 pm is stored as 20.15 in the database?
0
 

Author Comment

by:mguptill
ID: 36601916
Yes it is I don't care if it says AMor PM  here is some sample data

20.00 I still want the same format so in this case I would like 20.00 to reflect 20:00:00
0
 
LVL 13

Accepted Solution

by:
Wizilling earned 400 total points
ID: 36601947
declare @t numeric(5,2) = '8.30'

select substring(convert(varchar(100), cast(replace(CAST(@t as varchar(10)), '.', ':') as datetime), 120), 12,8)
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 100 total points
ID: 36602237
CONVERT(DATETIME,RIGHT('0'+replaCE(CONVERT(VARCHAR(5),convert(SMALLMONEY,starttime_t),0),'.',':'),5)+':00.000',8)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:mguptill
ID: 36709500
Thank you for your responses I'm sorry I didn't get back right away I had to go somewhere in a hurry. i will look at these and get back to you soon. again sorry for taking so long
0
 

Author Closing Comment

by:mguptill
ID: 36709564
Thank you both  for your solutions and they both worked but Wizilling's solution is what I needed although I will distribute the points accordingly because I believe in fairness and think Lowfatsread should get some points for his effort. Again I thank you both. Sorry lowfat i didn't need the date added.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36712028
I don't know why you don't do something simple like this:
DECLARE @starttime_t numeric(5,2)
SET @starttime_t = '8.20'
SELECT CONVERT(varchar(8), CONVERT(datetime, REPLACE(@starttime_t, '.', ':'), 8), 8)
0
 

Author Comment

by:mguptill
ID: 36718184
That works great ac thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now