My Visit table is the following:
insert into Visit
values(12, to_date(\'19-JUN-13\', \'dd-mon-yy\'), to_date(\'19-JUN-13 12:00 A.M.\' , \'dd-mon-yy hh:mi A.M
that is the oracle date format that is set as the default for your instance.
you should properly specify the format to see more or less.. something like this:
select to_char( datevisit, 'dd-mon-yy hh24:mi:ss' ) from visit
select localtimestamp from dual;
You're relying on implicit date conversion, which is using your (session-dependent, but maybe inherited from the DB default) NLS_DATE_FORMAT
setting - in this case that seems to be DD-MON-RR
.
You can use to_char
to specify the format, e.g.:
select to_char(actualarrivaltime, 'DD-MON-YYYY HH:M:SS PM') from ..
The datetime format models are described in the documentation.
In general it's better to never rely on implcit conversions. Even if you get what you expect now, they can be session-specific so another user in another client ,ight see something different. This can cause failures as well as just look wrong. Always specify date and number formats, using to_date
, to_char
, to_timestamp
etc.
Oracle internally follow 'DD-Mon-YY' format to store in database. So it returns'DD-Mon-Y
If you want to date format with hours min and sec. you can alter NLS_DATE_FORMAT in session.
If you want to query for the just Presentation purpose for that instance. Use TO_char Function to convert into required format.
SELECT slotnum, TO_CHAR (datevisit, 'DD-MON-YY ') "DATEVISIT",
TO_CHAR (actualarrivaltime, 'DD-MON-YY HH:MI:SS AM') "ACTUALARRIVALTIME"
FROM visit
I Hope the above query gives you the output as you like.
You can also set a format that applies to all dates like this:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH:MI:SS PM';
That way, your original query would output the dates in the format you're after, without using TO_CHAR
. To set back to the usual default format, just do this:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-RR';