ON DATES
<pre>SQL>
SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD/MM/YYYY HH24:MI:SS' ;
Session modifiée.
SQL>
SQL> -- Current date --
SQL> SELECT SYSDATE "Current date" FROM DUAL ;
Curent date
-------------------
08/10/2004 14:08:48
SQL>
SQL> -- date truncated to the 1st day of the year --
SQL> SELECT TRUNC(SYSDATE, 'YEAR') "'YEAR'" FROM DUAL;
'YEAR'
-------------------
01/01/2004 00:00:00
SQL>
SQL> -- date truncated to the 1st day of the ISO year --
SQL> SELECT TRUNC(SYSDATE, 'IYYY') "'IYYY'" FROM DUAL;
'IYYY'
-------------------
29/12/2003 00:00:00
SQL>
SQL> -- date truncated to the 1st day of the quarter --
SQL> SELECT TRUNC(SYSDATE, 'Q') "'Q'" FROM DUAL;
'Q'
-------------------
01/10/2004 00:00:00
SQL>
SQL> -- date truncated to the 1st day of the month --
SQL> SELECT TRUNC(SYSDATE, 'MONTH') "'MONTH'" FROM DUAL;
'MONTH'
-------------------
01/10/2004 00:00:00
SQL>
SQL> -- date truncated to the 1st day of the week --
SQL> SELECT TRUNC(SYSDATE, 'DAY') "'DAY'" FROM DUAL;
'DAY'
-------------------
04/10/2004 00:00:00
SQL>
SQL> -- day of the week corresponding to the 1st day of the month --
SQL> SELECT TRUNC(SYSDATE, 'W') "'W'" FROM DUAL;
'W'
-------------------
08/10/2004 00:00:00
SQL>
SQL> -- day of the week corresponding to the 1st day of the year --
SQL> SELECT TRUNC(SYSDATE, 'WW') "'WW'" FROM DUAL;
'WW'
-------------------
07/10/2004 00:00:00
SQL>
SQL> -- day of the week corresponding to the 1st day of the ISO year --
SQL> SELECT TRUNC(SYSDATE, 'IW') "'IW'" FROM DUAL;
'IW'
-------------------
04/10/2004 00:00:00
SQL>
SQL> -- date truncated to the day (suppress hours) --
SQL> SELECT TRUNC(SYSDATE, 'DD') "'DD'" FROM DUAL;
'DD'
-------------------
08/10/2004 00:00:00
SQL>
SQL> -- date truncated to the hour (suppress minutes) --
SQL> SELECT TRUNC(SYSDATE, 'HH') "'HH'" FROM DUAL;
'HH'
-------------------
08/10/2004 14:00:00
SQL>
SQL> -- date truncated to the minute (suppress seconds) --
SQL> SELECT TRUNC(SYSDATE, 'MI') "'MI'" FROM DUAL;
'MI'
-------------------
08/10/2004 14:08:00
No comments:
Post a Comment