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 ? | 137 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 trigger with example?
consider a table which contain 4 columns,ename,eno,sal and deptno, from this table i want to know ename who having maximum salary in deptno 10 and 20.
What is the difference between inner join and outer join?
what are the differences among rownum, rank and dense_rank? : Sql dba
- Types of triggers - View - Dcl - Procedures, packages, functions - Metasolve - Can use Dcl in triggers - package case study - Cursor and its types - triggers schedule - Wrap - Why we are using fetch and for in cursor. difference?
if we give update table_name set column_name= default. what will happen?
take one table is t1 and in that column name is f1 f1 column values are 200 5000 3000 7000 300 600 100 400 800 400 i want display the values asc and desc in a single output. sample output is f1.a 100 200 300 400 500 600 etc...... and f1.d is 5000 4000 3000 2000 1000 etc...
How are sql commands classified?
what are myisam tables? : Sql dba
What is asqueryable?
What are the subsets of sql?
What is a database? Explain