date - Sql Datetime convert -


in database table, have 2 column storing date , time in format:

   d30dat   d30tim     140224  75700 

i need update new field store date in format

2014-02-24 07:57:00.000 

how can use sql query it?

for postgres , oracle (assuming columns varchar):

select to_timestamp(dt, 'yymmdd hh24miss') (   select d30dat||' '||case when length(d30tim) = 5 '0'||d30tim else d30tim end dt   x ) t; 

the case expression adds leading 0 if time part consists of 5 digits format mask can specified 2 digits hour. blank between 2 columns debugging aid , left out.

the result real timestamp value can formatted using to_char() desired format.

sqlfiddle postgres: http://sqlfiddle.com/#!15/ac07a/2
sqlfiddle oracle: http://sqlfiddle.com/#!4/ac07a2/4


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -