Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge date and time columns

Tags:

sql

oracle

Currently I have 2 columns one that holds dates and the other holds the time (24hr text version).

Example:

a_dt          a_time_text
01-Jan-15     0224
31-Mar-15     0317
15-Sep-15     2010

How do I create a new column that hold the date and time, like this:

a_dt_tm
01-Jan-15 02:24
31-Mar-15 03:17
15-Sep-15 20:10

Or any other way so that I can find the difference in date/time between another variable.

like image 505
Amanda R. Avatar asked Jan 06 '23 15:01

Amanda R.


1 Answers

You can do this:

to_date
   ( to_char (a_dt,'YYYYMMDD')
        || a_time_text,
     'YYYYMMDDHH24MI'
   )

i.e. first convert the date column to a string - to_char (a_dt,'YYYYMMDD'), then append the time string, then convert the resulting string back to a date.

like image 174
Tony Andrews Avatar answered Jan 08 '23 09:01

Tony Andrews