I have a doc Column of Date Time format, but it always leaves the time blank, and I have a time field which is an integer which represents hours and minutes (not including seconds). I would like to convert the time and add it to the date so that I can select Max(datetime)
and return a single value.
Here is my SQL Fiddle.
The Data is stored as follows:
DocDate DocTime
2013-04-29 00:00:00.000 1416
2013-04-29 00:00:00.000 1027
2013-04-29 00:00:00.000 823
I'd like to convert it to:
DateTime
2013-04-29 14:16:00.000
2013-04-29 10:27:00.000
2013-04-29 08:23:00.000
Some simple date arithmetics will do it;
An SQLfiddle to test with.
Just treat them both as datetimes and add together:
See example: http://sqlfiddle.com/#!3/8e22e/54
see Sql fiddle
Using dateadd to add the hours ( left one or two chars of doctime) and the minutes (right 2 chars of doctime) to the date.
This should do:
And here is the modified sqlfiddle for you to try.