In this article we wre going to learn how to get current date with required format.
Query:
Output :
If we want to get sysdate in required format, then use the following syntax
Query:
Output :
MM – Prints month number (January – 01 , Feb – 02 ….).
DD – prints day number in a month.
YYYY – prints year number.
Some date & time Formats
Query:
SELECT SYSDATE FROM DUAL;
Output :
SYSDATE |
---|
07-MAR-16 |
If we want to get sysdate in required format, then use the following syntax
Query:
SELECT TO_CHAR( TRUNC(SYSDATE),’MM-DD-YYYY’) FROM DUAL;
Output :
SYSDATE |
---|
03-07-2016 |
MM – Prints month number (January – 01 , Feb – 02 ….).
DD – prints day number in a month.
YYYY – prints year number.
Some date & time Formats
FORMAT | DESSCRIPTION |
---|---|
DD | Represents day number in a month. |
DDD | Represents day number in a year[1-366] (for exmaple :091) |
D | Gives day number in a week[1-7] |
DAY | Gives day name Ex : sunday |
FMDAY | Gives day name without trailing spaces |
MM | Gives month number |
MON | Gives First three letters of month . Ex :FEB |
MONTH | Gives complete month name with trailing spaces. |
FMMONTH | Gives complete month without trailing spaces. |
YY | Gives last two digits of year |
YYYY | Gives year number. |
YEAR | Gives year in word format. Ex: TWENTY SIXTEEN |