oracle's trunc function

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; --Display current time
2011-12-29 16:24:34

select trunc(sysdate,'year') from dual; --Intercept to the year (the first day of this year)
2011-1-1

select trunc(sysdate,'q') from dual; --Intercept to the quarter (the first day of the quarter)
2011-10-1

select trunc(sysdate,'month') from dual; --Intercept to month (the first day of this month)
2011-12-1

select trunc(sysdate,'') from dual; 

select to_char(trunc(sysdate),'yyyymmdd hh24:mi:ss') from dual; --The default intercepts to the day (0:00:00:00 of the current day)
20111229 00:00:00

select trunc(sysdate-1,'w') from dual; -- the closest Thursday to the current time, if the current day is a Thursday, return the current day, otherwise return to the previous Thursday
2011-12-22

select trunc(sysdate,'ww') from dual; --Intercept to last weekend (last Saturday)
2011-12-24

select trunc(sysdate,'day') from dual; --Intercept to week (the first day of this week, that is, last Sunday)
2011-12-25

select trunc(sysdate,'iw') from dual; -- the second day of this week, which is Monday
2011-12-26

select to_char(trunc(sysdate,'dd'),'yyyymmdd hh24:mi:ss') from dual;--Intercept to the day (0:00:00:00 of the current day)
20111229 00:00:00

select trunc(sysdate,'hh24') from dual; --Intercept to the hour (current hour, zero minutes and zero seconds)
2011-12-29 16:00:00

select trunc(sysdate,'mi') from dual; --Intercept to minute (current minute, zero second)
2011-12-29 16:24:00

select trunc(sysdate,'ss') from dual ;--error, no format accurate to seconds

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326087611&siteId=291194637