In this article we wre going to learn how to get tomorrow and yesterday dates.
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+1 FROM DUAL; –prints tomorrow date
SELECT SYSDATE-1 FROM DUAL; –prints yesterday date
SELECT SYSDATE-1 FROM DUAL; –prints yesterday date
Output :
SYSDATE |
---|
08-MAR-16 |
If we want to get sysdate in required format, then use the following syntax
Query:
SELECT TO_CHAR( TRUNC(SYSDATE+1),’MM-DD-YYYY’) FROM DUAL; –prints tomorrow date
SELECT TO_CHAR( TRUNC(SYSDATE-1),’MM-DD-YYYY’) FROM DUAL; –prints yesterday date
SELECT TO_CHAR( TRUNC(SYSDATE-1),’MM-DD-YYYY’) FROM DUAL; –prints yesterday date
Output :
SYSDATE |
---|
03-08-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 |