Dates (and timestamps) do not have a format - they are represented internally by 7 or 8 bytes for a date or 20 bytes for a timestamp. The only time they are formatted is either when the user interface you are using implicitly converts then so it can display something meaningful to the user (i.e. when displaying a SELECT
statement) or when the user explicitly converts it using TO_CHAR
.
Given this, you do not need to change any format; just CAST
to a different data type:
SELECT CAST( your_timestamp_column AS DATE ) FROM your_table
Why does it display TIMESTAMP
s using 12 hour clock and DATE
s using 24 hour clock?
Because that's what your user interface has its defaults set to.
For SQL/Plus & SQL Developer the defaults are in the user's NLS session parameters:
SELECT parameter, value
FROM NLS_SESSION_PARAMETERS
WHERE parameter IN ( 'NLS_DATE_FORMAT', 'NLS_TIMESTAMP_FORMAT' );
You should see something like:
PARAMETER VALUE
-------------------- ---------------------------
NLS_DATE_FORMAT DD-MON-RR HH24:MI:SS
NLS_TIMESTAMP_FORMAT DD-MON-RR HH12:MI:SS.FF6 AM
You can alter them using:
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD"T"HH24:MI:SS';
ALTER SESSION SET NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD"T"HH24:MI:SS.FF9';
If, for example, you wanted them both in ISO8601 format.