datetime - subtracting time for date time in SQL Developer -


i using sql developer (3.1.06) pull information dwhp. want subtract time (hh:mm:ss)--> timecol_3 date time (dd/mm/yy hh:mm:ss)-->datetime_col4, (10/01/15 01:00:00)-(03:00:00) should display (09/01/15 22:00:00).

now date time wasnt combined intially , neither in above format. (they in mm/dd/yyyy , hhmma or hhmmp format), used following syntax bring (dd/mm/yy hh:mm:ss) format-->

to_char(to_date(datecol_1 || ' ' || timecol2, 'dd/mm/yy hh24:mi:ss'), 'dd/mm/yy hh24:mi:ss') datetime_col4

could please help??

it looks data in string format (based on manipulations performed in bolded text):

to_char(to_date(datecol_1 || ' ' || timecol2, 'dd/mm/yy hh24:mi:ss'), 'dd/mm/yy hh24:mi:ss') datetime_col4

in oracle it's best work dates in native date type rather converting them , character data types, datetime_col4 better represented so:

to_date(datecol_1 || ' ' || timecol2, 'dd/mm/yy hh24:mi:ss') datetime_col4 

now assuming timecol_3 character string in hh24:mi:ss form hh24 portion ranges between 00 , 23, can cast timecol_3 interval data type (the closest data type oracle has pure time data type) so:

cast('0 '||timecol_3 interval day second) timecol3 

you need leading '0 ' when casting interval represent day portion of interval, in case 0 days.

interval data types can added , subtracted , each other , and date[time] data types natively in oracle, final result date date type (starting base columns):

  to_date(datecol_1 || ' ' || timecol2, 'dd/mm/yy hh24:mi:ss') - cast('0 '||timecol_3 interval day second) result 

you can wrap final to_char() display results in desired format, or change nls_date_format session setting output date data types in desired format:

alter session nls_date_format = 'dd/mm/yy hh24:mi:ss'; 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -