what is the difference between to_char and to_date
functions?

Answers were Sorted based on User's Feedback



what is the difference between to_char and to_date functions?..

Answer / rajesh

to_char function is used to convert the given data into
character....
eg:to_char(sysdate,'month') which returns month alone...

to_date is used to convert the given data into date data
formate data type....

eg: to_date('070903', 'MMDDYY') would return a date value
of July 9, 2003.

Is This Answer Correct ?    137 Yes 33 No

what is the difference between to_char and to_date functions?..

Answer / jacob

try this out
select to_char(sysdate,' Day "," DDsp"th " Month Year') from
dual

this gives the day,date,month,year of the current date

Is This Answer Correct ?    43 Yes 15 No

what is the difference between to_char and to_date functions?..

Answer / 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

what is the difference between to_char and to_date functions?..

Answer / sanjukata

to_char()is required to convert number type and date type
of value to character type.

try this
select ename,hiredate,to_char(hiredate,'day ddth mon yy')
from emp;

to_date()is required to convert charater type of value to
date type.
try this
select to_date('22092010','dd-mm-yy')from dual;

Is This Answer Correct ?    15 Yes 3 No

what is the difference between to_char and to_date functions?..

Answer / naveen

to_char function is used to convert the given data into
character....
eg:to_char(sysdate,'month') which returns month alone...

to_date is used to convert the given data into date data
formate data type....

eg: to_date('070903', 'MMDDYY') would return a date value
of July 9, 2003.

Is This Answer Correct ?    10 Yes 0 No

what is the difference between to_char and to_date functions?..

Answer / sushant butta

Check the answer in detail here. http://www.oraclebin.com/2012/12/what-is-difference-between-tochar-and.html

A lot of people have confusion about the usage of to_char and to_date functions. When to use to_char and when to use to_date. Here I am going to tell you how to do that. I will be discussing to_char function with respect to date only and not with numbers.

Syntax
to_char(value , format_mask)

to_date(string , format_mask)

So when you want to convert a date to a string use to_char function. Always remember that INPUT to to_char function is always a date (excluding numbers here). A format mask over here decides how OUTPUT of to_char function will look. Lets consider this with an example.



sql > Select to_char(sysdate,'DD-MM-YYYY') from dual;

Output : 01-01-2001

INPUT -> sysdate ( a date)
OUTPUT -> 01-01-2001 ( DD-MM-YYYY the format mask)

And when you want to convert a string to a date use to_date function. Always remember that OUTPUT of to_date function is always a date. A format mask over here decides what will the format of INPUT string. Lets have an example.

sql > select to_date( '01-01-2001','DD-MM-YYYY') from dual;

Output : 01-JAN-01

INPUT -> 01-01-2001 ( format_mask is 'DD-MM-YYYY')
OUTPUT -> 01-JAN-01 ( a date, the format here is the default NLS setting for your date)


Just remember the input and output of these functions and you will never make a mistake.

Is This Answer Correct ?    8 Yes 4 No

what is the difference between to_char and to_date functions?..

Answer / madhu

The Simple examples is correct but we take the date in date
format not like sysdate or hiredate.
if u select to_char('some date') and to_date('somedate')
explain with this examples if any one know.

Is This Answer Correct ?    7 Yes 6 No

what is the difference between to_char and to_date functions?..

Answer / m

to_char conversion function will convert given data to character data whereas to_data will convert given character data into date format model.


Also we can say like to_char conversion function use for convert invalid data into valid data.
and to_date conversion function will convert valid data into invalid.

Is This Answer Correct ?    1 Yes 0 No

what is the difference between to_char and to_date functions?..

Answer / susan

To_char is to convert number or date(string format) to character format.
To_date is from character format to date,only fetches d data when dere s valid number..

Is This Answer Correct ?    2 Yes 5 No

what is the difference between to_char and to_date functions?..

Answer / xc

cxc

Is This Answer Correct ?    5 Yes 22 No

Post New Answer

More SQL PLSQL Interview Questions

What are records give examples?

0 Answers  


What are the methods of filing?

0 Answers  


What is the use of sqldataadapter?

0 Answers  


How much ram can sql express use?

0 Answers  


What is posting?

0 Answers  






Which one of the following pairs of aggregate functions do you use with character fields? 1. COUNT(field) and MAX(field) 2. AVG(field) and COUNT(field) 3. MIN(field) and SUM(field) 4. AVG(field) and MAX(field) 5. COUNT(field) and SUM(field)

6 Answers   HCL,


What does varchar include?

0 Answers  


What is delimiter sql?

0 Answers  


Which is faster view or stored procedure?

0 Answers  


Is primary key clustered or nonclustered?

0 Answers  


How do you retrieve set of records from database server. {Set max records = 100 & use paging where pager page no or records = 10 & after displaying 100 records again connect to database retrieve next 100 }

2 Answers   DELL,


How do I run a query in pl sql developer?

0 Answers  


Categories