Friday, 11 May 2018

Working with TRUNC function Options

Below are the some of the options which i use with TRUNC functions.

may be useful somewhere to you.


SELECT SYSDATE FRom dual --Display Current Date with time stamp

SELECT trunc(SYSDATE) FRom dual --Display Current Date without time stamp

SELECT TRUNC(SYSDATE) FRom dual --Display 1st Day of Current Year

SELECT TRUNC(SYSDATE,'MM') FRom dual --Display 1st Day of Current Month

SELECT TRUNC(SYSDATE,'DD') FRom dual --Display Current system date

SELECT TRUNC(SYSDATE,'D') FRom dual --Display 1st Day of the Current week, generally week starts from Sunday so it displays Sunday date for that week

SELECT TRUNC(SYSDATE,'Y') FRom dual --Display 1st Day of Current Year



SQL> 
SQL> SELECT SYSDATE FRom dual;
 
SYSDATE
-----------
5/11/2018 2
SQL> 
  2  SELECT trunc(SYSDATE) FRom dual;
 
TRUNC(SYSDATE)
--------------
5/11/2018
SQL> 
  2  SELECT TRUNC(SYSDATE) FRom dual;
 
TRUNC(SYSDATE)
--------------
5/11/2018
SQL> 
  2  SELECT TRUNC(SYSDATE,'MM') FRom dual;
 
TRUNC(SYSDATE,'MM')
-------------------
5/1/2018
SQL> 
  2  SELECT TRUNC(SYSDATE,'DD') FRom dual;
 
TRUNC(SYSDATE,'DD')
-------------------
5/11/2018
SQL> 
  2  SELECT TRUNC(SYSDATE,'D') FRom dual;
 
TRUNC(SYSDATE,'D')
------------------
5/6/2018
SQL> 
  2  SELECT TRUNC(SYSDATE,'Y') FRom dual;
 
TRUNC(SYSDATE,'Y')
------------------
1/1/2018