Like I said, timestamps always have a date component. If you to_timestamp a "time", Oracle Database defaults the date to the start of the current month:
alter system set fixed_date = '2015-01-28 00:00:00';
select sysdate, to_timestamp( '10:00 AM','HH:MI AM' ) t from dual;
SYSDATE T
28-JAN-2015 00:00:00 01-JAN-2015 10.00.00.000000000
alter system set fixed_date = none;
select sysdate, to_timestamp( '10:00 AM','HH:MI AM' ) t from dual;
SYSDATE T
21-AUG-2017 04:07:36 01-AUG-2017 10.00.00.000000000
Specify a date explicitly to so you store the "correct" date (whatever that is).
If you want to get just the time back, you have a few options:
- to_char the columns in your query
- Store the times in a varcahr2 to start with
- Use a virtual column and extract the time in that
e.g.:
create table t (
ts timestamp,
tm varchar2(10),
ts_vc as ( to_char ( ts, 'hh:mi am' ) )
);
insert into t (ts, tm)
values (systimestamp, to_char(systimestamp, 'hh:mi am'));
select to_char(ts, 'hh:mi am'), tm, ts_vc from t;
TO_CHAR(TS,'HH:MIAM') TM TS_VC
04:12 am 04:12 AM 04:12 am