Oracle date functions
Date and character conversion function usage (to_date, to_char)
Select to_char (sysdate, 'yyyy-mm-dd hh24: mi: ss') as nowTime from dual; // convert a date to a string select to_char (sysdate, 'yyyy ') as nowYear from dual; // obtain the year's select to_char (sysdate, 'mm') as nowMonth from dual; // obtain the month's select to_char (sysdate, 'dd ') as nowDay from dual; // select to_char (sysdate, 'hh24') as nowHour from dual; // select to_char (sysdate, 'mi') when obtaining the time ') as nowMinute from dual; // obtain the Time of the minute select to_char (sysdate, 'ss') as nowSecond from dual; // obtain the time of the second
Calculate the day of the week in SQL> select to_char (to_date ('1970-10-27 ', 'yyyy-mm-dd'), 'day') from dual; TO_CHA ------ the number of days during the Tuesday period SQL> select floor (sysdate-to_date ('123456', 'yyyymmdd') from dual; FLOOR (SYSDATE-TO_DATE ('123456 ', 'yyyymmdd') ------------------------------------------------- processing of the Month/Sept.
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 ) )
Method for processing the number of days in a month: select to_char (add_months (last_day (sysdate) + 1,-2), 'yyyymmdd'), last_day (sysdate) from dual