Sri
Sri

Reputation: 179

What is difference between TO_CHAR and TO_DATE

I'm running two queries

  1. select TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS PM') from dual; It displays date with exact time.

  2. select TO_DATE(SYSDATE, 'DD-MON-YYYY HH:MI:SS PM') from dual; It displays date with default time 12:00:00 AM.

I do not understand TO_CHAR and TO_DATE usage. How to display date with exact time by using TO_DATE

Upvotes: 1

Views: 42592

Answers (1)

Nazmul
Nazmul

Reputation: 595

to_char function is used to convert the given data into character....

SQL> SELECT TO_CHAR(SYSDATE, 'dd/mm/yyyy') FROM dual;

TO_CHAR(SY
------------------
04/04/2012

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.

Reference: Interview Question

Upvotes: 1

Related Questions