Click here to Skip to main content
15,888,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have field in db table which have real datatype in SQL 2005. I want to convert it into time (HH:MM) format and add to another time.

ex:
0.3 (convert it to 00:30) and want to add into 17:45 so i can get 18:15
0.45(convert it to 00:45) and want to add into 17:45 so i can get 18:30
1(convert it to 01:00) and want to add into 17:45 so i can get 18:45

Thanks.
Posted
Comments
Maciej Los 29-Jul-14 4:21am    
0.3 is not equal to half an hour (30 minutes)! 60*0.3= 18 minutes. But NOT 30 minutes!
kk2014 29-Jul-14 4:54am    
yes you are right. first need to convert 0.3 into 00:30 min.

1 solution

Please, read my comment to the question.

SQL
DECLARE @rtime REAL 

SET @rtime = 0.3

SELECT @rtime AS rTime , @rtime *60 AS RealTime, DATEADD(MINUTE  , @rtime *60, '2014-07-29 17:45:00') AS NewTime


For further information, please see: DATEADD[^]
 
Share this answer
 
Comments
kk2014 29-Jul-14 4:54am    
first need to convert 0.3 into 00:30 min which means half n hour.
your solution will give answer 2014-07-29 18:03:00.000.
it should get 2014-07-29 18:15:00.000.
Maciej Los 29-Jul-14 5:34am    
No, it shouldn't. If 1 is equal to 1 hr, then 0.3 is equal to 18 mins. In case when 0.6 will be equal to 1 hr, i would agree with you.
kk2014 29-Jul-14 5:44am    
hello,
please read post carefully. 0.3 is real and need to convert into time(HH:MM).
Maciej Los 29-Jul-14 5:47am    
I read it carefully. I'm trying to tell you that the 0.3 can't be equal to 0.5 hour. Logic!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900