2

How to combine two values into a datetime field

 Example value 1 = 2010-10-26 00:00:00.000 (datetime)
 Example value 2 = 1650 (varchar)

 Desire Result 2010-10-26 16:50:00.00
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jason312
  • 197
  • 1
  • 1
  • 10

1 Answers1

2

You can add datetimes together in SQL Server. The trick is getting the time from the second one:

select (value1 +
        cast(cast(stuff(value2, 3, 0, ':') as time) as datetime)
       )

Alternatively, if value2 is an integer, you could do:

select dateadd(minute,
               (value2/100)*60 + value2%100,
               value1
              )
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786