Oracle time function usage

select sysdate from dual--return system time

select trunc(sysdate) from dual

select trunc(sysdate-8) from dual

select trunc(sysdate+8) from dual

select trunc(sysdate-to_date('2015-2-18','yyyy-MM-dd')) from dual--system time-specified time

select trunc(to_date('2015-2-20','yyyy-MM-dd')-8) from dual--specified time plus or minus days

select trunc(to_date('2015-2-20','yyyy-MM-dd')+8) from dual

select trunc(sysdate+(INTERVAL '1' DAY)  ) from dual  --加1天(1)

select trunc(sysdate+(INTERVAL '1' MONTH) ) from dual --加1月

select trunc(sysdate+(INTERVAL '1' YEAR) ) from dual --加1年

select trunc(to_date('2015-2-20','yyyy-MM-dd')+(INTERVAL '1' DAY)) from dual --加1天(1)

select sysdate,last_day(sysdate) from dual;--return the date of the last day of the month

select trunc(28.4), trunc(28.9), trunc(sysdate) from dual;--only integers

select round(28.4),round(28.9) from dual;--round 5 for all types 4

---

select to_date('2015-2-18','yyyy-MM-dd'),-- the date at that time,

 round(to_date('2015-2-18','yyyy-MM-dd')),-- today's date,

 round(to_date('2015-2-18','yyyy-MM-dd'),'day'),-- Sunday this week,

 round(to_date('2015-2-18','yyyy-MM-dd'),'month') ,--the beginning of this month,

 round(to_date('2015-2-18','yyyy-MM-dd'),'q'),-- the date of the beginning of the season, 

 round(to_date('2015-2-18','yyyy-MM-dd'),'year')-- the date at the beginning of the year 

from dual;

--

select sysdate ,--the current date,

 next_day(sysdate,'Monday'),-- Monday of the next week,

 next_day(sysdate,'Tuesday'),-- Tuesday next week,

 next_day(sysdate,'Wednesday'),-- Wednesday next week,

 next_day(sysdate,'Thursday'),-- Thursday next week,

 next_day(sysdate,'Friday'),-- Friday next week,

 next_day(sysdate,'Saturday'),-- next Saturday,

 next_day(sysdate,'Sunday')-- Sunday of the next week 

from dual;

---

select 

 extract(hour from timestamp '2001-2-16 2:38:40 ' ),-- 小时,

 extract(minute from timestamp '2001-2-16 2:38:40 ' ) ,--分钟,

 extract(second from timestamp '2001-2-16 2:38:40 ' ),-- 秒,

 extract(DAY from timestamp '2001-2-16 2:38:40 ' ) ,--日,

 extract(MONTH from timestamp '2001-2-16 2:38:40 ' ) ,--月,

 extract(YEAR from timestamp '2001-2-16 2:38:40 ' )-- 年

from dual;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608802&siteId=291194637