I am running some queries to track down a problem with our backup logs and would like to display datetime fields in 24-hour military time. Is there a simple way to do this? I've tried googling and could find nothing.
You can use TO_CHAR in a query to display a DATE in any particular format, but, as you said, that makes the column a string, not a DATE. Usually, that doesn't matter. ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';SELECT hiredate, ...
The date format along with timestamp components : YYYY-MM-DD hh:mm:ss. YYYY-MM-DDThh:mm:ss. YYYY-MM-DD hh:mm:ss.
We are using sysdate to fetch date and time from the system also time format is set to 12 hours. SELECT TO_CHAR(sysdate, 'DD-MM-YYYY HH:MI:SS AM') As "Date format AM/PM" FROM dual; Output: In the below output, Date, time, and AM/PM format is displayed using to_char format in the oracle database.
Oracle Database has five date-time data types: TIMESTAMP. TIMESTAMP WITH TIME ZONE. TIMESTAMP WITH LOCAL TIME ZONE.
select to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
Give the time in 24 hour format.
More options are described here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With