This article to share the Oracle trunc function processing date format related knowledge, very has the reference value, concrete please see below explanation.
Copy Code code as follows:
Select To_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') from dual; --Show Current time
2011-12-29 16:24:34
Copy Code code as follows:
Select Trunc (Sysdate, ' year ') from dual; --Interception to year (first day of this year)
2011-1-1
Copy Code code as follows:
Select Trunc (sysdate, ' Q ') from dual; --intercept to quarter (first day of this quarter)
2011-10-1
Copy Code code as follows:
Select Trunc (sysdate, ' month ') from dual; --Interception to month (first day of this month)
2011-12-1
Copy Code code as follows:
Select Trunc (sysdate, ') from dual;
Empty
Copy Code code as follows:
Select To_char (trunc (sysdate), ' Yyyymmdd Hh24:mi:ss ') from dual; --The default interception to the day (0 minutes 0 seconds of the day)
20111229 00:00:00
Copy Code code as follows:
Select Trunc (sysdate-1, ' W ') from dual; --The nearest Thursday to the current time, if the day is Thursday, return the same day, otherwise return to Thursday
2011-12-22
Copy Code code as follows:
Select Trunc (sysdate, ' WW ') from dual; --Interception to last weekend (last Saturday)
2011-12-24
Copy Code code as follows:
Select Trunc (sysdate, ' Day ') from dual; --Intercept to week (the first day of this week, that is, Sunday)
2011-12-25
Copy Code code as follows:
Select Trunc (sysdate, ' IW ') from dual; --On the 2nd day of this week, this Monday
2011-12-26
Copy Code code as follows:
Select To_char (trunc (sysdate, ' DD '), ' YYYYMMDD hh24:mi:ss ') from dual;--intercept to day (0 minutes 0 seconds of the day)
20111229 00:00:00
Copy Code code as follows:
Select Trunc (sysdate, ' hh24 ') from dual; --intercept to hour (current hour, 0 minutes 0 seconds)
2011-12-29 16:00:00
Copy Code code as follows:
Select Trunc (sysdate, ' mi ') from dual; --intercept to minute (current minute, 0 seconds)
2011-12-29 16:24:00
Copy Code code as follows:
Select Trunc (sysdate, ' SS ') from dual;--error, no format accurate to second
About Oracle trunc function processing date format This is the end, I hope you like it.