Solved

Convert Numeric field to Time

Posted on 2011-09-26
8
312 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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
 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need time in SQL 8 30
SQL Add Parameter in Variable 4 21
Need help with a query 14 32
Cannot connect to SQL express 2008 R2 installed on Server 2016 5 15
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

685 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