Partial usage of oracle date function
ORACLE Date and Time Functions
Date and character conversion function usage (to_date,to_char)
select to_char(sysdate,'y-mm-dd hh34:mi: ss') as nowTime from dual; //date converted to string
select to_char(sysdate,'y') as nowYear from dual; //get the year of the time
select to_char(sysdate,'mm') as nowMonth from dual; //get month of time
select to_char(sysdate,'dd') as nowDay from dual; //get the day of the time
select to_char(sysdate,'hh34') as nowHour from dual; //get time when
select to_char(sysdate,'mi') as nowMinute from dual; //Get the minutes of the time
select to_char(sysdate,'ss') as nowSecond from dual; //Get the seconds of the time
Ask what day of the week it is.
SQL> select to_char(to_date('2015-10-27','yyyy-mm-dd'),'day') from dual;
TO_CHA
------
Tuesday
Number of days between two days
SQL> select floor(sysdate - to_date('20020405','yyyymmdd')) from dual;
FLOOR(SYSDATE-TO_DATE('20020405','YYYYMMDD'))
---------------------------------------------
4949
Date of treatment
select older_date,
newer_date,
years,
months,
abs(
trunc(
newer_date-
add_months( older_date,years*12+months )
)
) days from ( select
trunc(months_between( newer_date, older_date )/12) YEARS,
mod(trunc(months_between( newer_date, older_date )),12 ) MONTHS,
newer_date,
older_date
from (
select hiredate older_date, add_months(hiredate,rownum)+rownum newer_date
from emp
)
)
Ways to deal with the uncertainty of the number of days in the month
select to_char(add_months(last_day(sysdate) +1, -2), 'yyyymmdd'),last_day(sysdate) from dual
Original address; plat.delit.cn/thread-183-1-1.html
Please indicate the source of the reprint;
Written by Metrology www.delit.cn