A to_char function is useful while displaying oracle date value to a required string format.This is particularly useful for displaying the dates in the most suitable format required.Few examples of using this method with different formats given below.
See the below example for to_char function usage.
<pre>-- Created on 11/19/2008 by Globinch PLSQLTIPS
declare
-- Local variables here
test_Date DATE;
begin
-- Initialize the date
test_Date := to_date('12/12/2008','DD/MM/YYYY');
--To display day and all other details
dbms_output.put_line('The date :' || to_char(test_Date,'Dy DD-MM-YYYY HH24:MI:SS'));
--To display month in text
dbms_output.put_line('The date :' ||to_char(test_Date,'Dy DD-MON-YYYY HH24:MI:SS'));
--To display 12HR format and milliseconds
dbms_output.put_line('The date :' || to_char(sysdate,'YYYY/MM/DD HH12:MI:SS:ssss'));
--To display AM/PM format
dbms_output.put_line('The date :' || to_char(sysdate,'YYYY/MM/DD HH12:MI:SS:ssss AM '));
end;
/
The date :Fri 12-12-2008 00:00:00
The date :Fri 12-DEC-2008 00:00:00
The date :2008/11/19 03:29:15:1515
Read,
- Using oracle date format |Using the DATE Format Mask in pl/sql
- Oracle comparing dates : dates, oracle, date comparison in oracle pl/sql
- ORA-01882: TIMEZONE REGION NOT FOUND |Oracle Error
- PL/SQL EXTRACT function for oracle datetime
- ALTER TABLE to ADD PRIMARY KEY in Oracle| Oracle ALTER TABLE
- oracle date difference | date difference in sql an…
- DATE Data type in Oracle|Oracle Dates and Times|Dates in Oracle
- Formatting date in SQL (Oracle) -Simple date forma…
- Database Schema | Oracle Schema Objects | What is database schema?
- Autonomous Transactions in PL/SQL
- SQL – Transaction Statements -Transaction Manageme…
- Savepoints In SQL Transactions. – SAVEPOINT
- Oracle Tablespace, and Datafiles – Introduction
- Formatting date in SQL (Oracle) -Simple date forma…
- FINDING database objects, finding valid and INVALI…
Technorati Tags:
oracle date format, date format, sql date, to_date, to_char
