what is the difference between to_char and to_date
functions?
Answers were Sorted based on User's Feedback
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 ? | 138 Yes | 33 No |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 pivot table in sql?
What will you get by the cursor attribute sql%notfound?
What is sql query limit?
Show how functions and procedures are called in a pl/sql block.
How can we make an if statement within a select statement?
How to generate a salary slip like jan 1000 1000 feb 1000 2000 ... dec 1000 12000
what are the other commands to know the structure of table using mysql commands except explain command? : Sql dba
What are the 3 modes of parameter?
What are the advantages of the packages
what is view? : Sql dba
sql query to get zero records from a table having n no of records
what is External tables? explain with examples