By default, the database outputs dates in the format DD-MON-YY, where
YY are the last two digits of the year.
SQL>
SQL> -- create demo table
SQL> create table Employee(
2 ID VARCHAR2(4 BYTE) NOT NULL,
3 First_Name VARCHAR2(10 BYTE),
4 Last_Name VARCHAR2(10 BYTE),
5 Start_Date DATE,
6 End_Date DATE,
7 Salary Number(8,2),
8 City VARCHAR2(10 BYTE),
9 Description VARCHAR2(15 BYTE)
10 )
11 /
Table created.
SQL>
SQL> -- prepare data
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values ('01','Jason', 'Martin', to_date('19960725','YYYYMMDD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Programmer')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('02','Alison', 'Mathews', to_date('19760321','YYYYMMDD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver','Tester')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('03','James', 'Smith', to_date('19781212','YYYYMMDD'), to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver','Tester')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('04','Celia', 'Rice', to_date('19821024','YYYYMMDD'), to_date('19990421','YYYYMMDD'), 2344.78, 'Vancouver','Manager')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('05','Robert', 'Black', to_date('19840115','YYYYMMDD'), to_date('19980808','YYYYMMDD'), 2334.78, 'Vancouver','Tester')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('06','Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78,'New York', 'Tester')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('07','David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78,'New York', 'Manager')
3 /
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('08','James', 'Cat', to_date('19960917','YYYYMMDD'), to_date('20020415','YYYYMMDD'), 1232.78,'Vancouver', 'Tester')
3 /
1 row created.
SQL>
SQL>
SQL>
SQL> -- display data in the table
SQL> select * from Employee
2 /
ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION
---- ---------- ---------- --------- --------- ---------- ---------- ---------------
01 Jason Martin 25-JUL-96 25-JUL-06 1234.56 Toronto Programmer
02 Alison Mathews 21-MAR-76 21-FEB-86 6661.78 Vancouver Tester
03 James Smith 12-DEC-78 15-MAR-90 6544.78 Vancouver Tester
04 Celia Rice 24-OCT-82 21-APR-99 2344.78 Vancouver Manager
05 Robert Black 15-JAN-84 08-AUG-98 2334.78 Vancouver Tester
06 Linda Green 30-JUL-87 04-JAN-96 4322.78 New York Tester
07 David Larry 31-DEC-90 12-FEB-98 7897.78 New York Manager
08 James Cat 17-SEP-96 15-APR-02 1232.78 Vancouver Tester
8 rows selected.
SQL>
SQL>
SQL>
SQL>
SQL>
SQL> -- clean the table
SQL> drop table Employee
2 /
Table dropped.
10.7.Date Format |
| 10.7.1. | Insert Date value with default format |
| 10.7.2. | By default, the database outputs dates in the format DD-MON-YY |
| 10.7.3. | Datetime Formatting Parameters for TO_CHAR() function |
| 10.7.4. | SELECT TO_CHAR(ADD_MONTHS(TO_DATE('01-JAN-2005 19:15:26','DD-MON-YYYY HH24:MI:SS'), 2), 'DD-MON-YYYY HH24:MI:SS') FROM dual; |
| 10.7.5. | CC: Two-digit century |
| 10.7.6. | SCC: Two-digit century with a negative sign (-) for B.C. |
| 10.7.7. | Q: One-digit quarter of the year |
| 10.7.8. | YYYY: All four digits of the year |
| 10.7.9. | IYYY: All four digits of the ISO year |
| 10.7.10. | RRRR: All four digits of the rounded year, which depends on the current year |
| 10.7.11. | SYYYY: All four digits of the year with a negative sign (-) for B.C. |
| 10.7.12. | Y,YYY: All four digits of the year with a comma |
| 10.7.13. | YYY: Last three digits of the year |
| 10.7.14. | IYY: Last three digits of the ISO year |
| 10.7.15. | YY: Last two digits of the year |
| 10.7.16. | IY: Last two digits of the ISO year |
| 10.7.17. | RR: Last two digits of the rounded year, which depends on the current year |
| 10.7.18. | Y: Last digit of the year |
| 10.7.19. | I: Last digit of the ISO year |
| 10.7.20. | YEAR: Name of the year in uppercase |
| 10.7.21. | Year: Name of the year with the first letter in uppercase |
| 10.7.22. | MM: Two-digit month of the year |
| 10.7.23. | MONTH: Full name of the month in uppercase, right-padded with spaces to a total length of nine characters |
| 10.7.24. | Month: Full name of the month with first letter in uppercase, right-padded with spaces to a total length of nine characters |
| 10.7.25. | MON: First three letters of the name of the month in uppercase |
| 10.7.26. | Mon: First three letters of the name of the month with the first letter in uppercase |
| 10.7.27. | RM:Roman numeral month. |
| 10.7.28. | WW: Two-digit week of the year |
| 10.7.29. | IW: Two-digit ISO week of the year |
| 10.7.30. | W: One-digit week of the month |
| 10.7.31. | DDD: Three-digit day of the year |
| 10.7.32. | DD:Two-digit day of the month |
| 10.7.33. | D: One-digit day of the week |
| 10.7.34. | DAY: Full name of the day in uppercase |
| 10.7.35. | Day: Full name of the day with the first letter in uppercase |
| 10.7.36. | DY: First three letters of the name of the day in uppercase |
| 10.7.37. | Dy: First three letters of the name of the day with the first letter in uppercase |
| 10.7.38. | J: Julian day-the number of days that have passed since January 1, 4713 B.C. |
| 10.7.39. | HH24: Two-digit hour in 24-hour format |
| 10.7.40. | HH: Two-digit hour in 12-hour format |
| 10.7.41. | MI: Two-digit minute |
| 10.7.42. | SS: Two-digit second |
| 10.7.43. | -/,.;: 'text' |
| 10.7.44. | SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY') |
| 10.7.45. | AM or PM: AM or PM as appropriate |
| 10.7.46. | SELECT TO_CHAR(SYSDATE, 'PM') |
| 10.7.47. | A.M. or P.M.: A.M. or P.M. as appropriate (2) |
| 10.7.48. | SELECT TO_CHAR(SYSDATE, 'P.M.') (2) |
| 10.7.49. | AD or BC: AD or BC as appropriate |
| 10.7.50. | TO_CHAR(SYSDATE, 'BC') |
| 10.7.51. | A.D. or B.C.: A.D. or B.C. as appropriate (2) |
| 10.7.52. | TO_CHAR(SYSDATE, 'B.C.') (2) |
| 10.7.53. | DDSPTH 'of' MONTH, YEAR A.D. |
| 10.7.54. | DAY MON, YY AD |
| 10.7.55. | SELECT TO_CHAR(TO_DATE('05-FEB-1968'), 'MONTH DD, YYYY') |