Get time and date from oracle database

select sysdate from dual;--current system time
--year
select trunc(sysdate,'yyyy') from dual;--get the first day of the year
select last_day(add_months(trunc(SYSDATE,'yyyy'),11)) from dual;--get the last day of the year
--moon
select trunc(sysdate,'mm') from dual;--get the first day of the month this year
select last_day(trunc(sysdate,'mm')) from dual;--Get the last day of this month this year
--day
select trunc(sysdate) from dual;--get today's date
select trunc(sysdate-1) from dual;--get yesterday
select add_months(trunc(sysdate,'mm'),-1) from dual;--Get the first day of the previous month
--The hour, minute and second are 00:00:00
select to_char (trunc(SYSDATE-1),'yyyy-mm-dd HH24:MI:SS')  from dual;

-- the first day of next year
select to_char (add_months(trunc(SYSDATE,'yyyy'),12),'yyyy-mm-dd HH24:MI:SS')  from dual;

-- the first day of the year
select to_char(trunc(SYSDATE,'yyyy'),'yyyy-mm-dd HH24:MI:SS')  from dual;
-- Calculate the date as the day of the week. Since the first day of each week is Sunday, you need to subtract 1 from the date
select to_char(to_date(20170419,'yyyymmdd')-1,'d') from dual;

 

Guess you like

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