what is the difference between to_char and to_date
functions?

Answer Posted / kushal

to_char is used to convert dates into a character
representation, for example, if you want your query to
format the date differently:

i.e.
SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') FROM
dual; --> 09/06/2004 12:57:54
SELECT TO_CHAR(SYSDATE, 'Day ddth Month') FROM
dual; --> Wednesday 09th June

The to_date function is used when you have character input,
but need it as a date object (for example when the database
column is a Date, you need to insert a date)

i.e.
SELECT TO_DATE('01/01/2004', 'DD/MM/YYYY') FROM dual
SELECT TO_DATE('01/01/2004 13:13:13', 'DD/MM/YYYY
HH24:MI:SS') FROM dual

@madhu:-sysdate bydefault gives the date in
dateformat,which is prerequisite of the to_char.
For other dates we have to convert first in date format and
then operate to_char accordingly to change the format as
needed for the date.

Is This Answer Correct ?    31 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is rtm in testing?

566


Which kind of parameters cannot have a default value in pl sql?

585


What is write ahead logging in sql server?

553


How many rows can sqlite handle?

576


What is the difference between nested table and varray?

510






What is sql keyword?

547


Which are the different case manipulation functions in sql?

528


What is sql*loader and what is it used for? : aql loader

609


How are functions and procedures called in PL/SQL?

582


name 3 ways to get an accurate count of the number of records in a table? : Sql dba

555


What is sequence in sql?

498


What is primary key secondary key alternate key candidate key?

535


define data blocks ? : Sql dba

536


Which normal form is best?

507


Enlist some predefined exceptions?

570