Using SQl Server 2000
Table
time (varchar)
2
1.5
3
5
2
2.5
...
I want to conver the time in datetime format like this 02:00 (HH:MM), 2.5 or 1.5 should be 02:30 hours, 01:30 Hours
Expected output
time (varchar)
02:00
01:30
03:00
05:00
02:00
02:30
...
how to do this in sql
Need sql query help
Actually, this may be much easier (you can
CASTtotimeordatetime)But if you want a
varcharimplementationWhere
nis your number.LTRIMis used as a simple way to convert the numbers intovarchar. WeCASTnto anintto grab the hour portion, then we get the remainder fromnto get the remaining fraction of an hour and convert to minutes with* 60. Then weCASTthe minutes tointto truncate the decimal places, useRIGHTand pad a zero to the left to ensure that it is exactly two characters wide.