Oracle gets this week, this month, the season, the first day of the year, and the last day
--This week
Select Trunc (sysdate, ' d ') + 1 from dual;
Select Trunc (sysdate, ' d ') + 7 from dual;
--This month
Select Trunc (sysdate, ' mm ') from dual;
Select Last_day (trunc (sysdate)) from dual;
--this season
Select Trunc (sysdate, ' Q ') from dual;
Select Add_months (trunc (sysdate, ' Q '), 3)-1 from dual;
--this year
Select Trunc (sysdate, ' yyyy ') from dual;
Select Add_months (trunc (sysdate, ' yyyy '), 1 from dual;
--Get start time and end time of last month
Select To_char (To_date (To_char (Add_months (Sysdate,-1), ' yyyy-mm '), ' yyyy-mm '), ' Yyyy-mm-dd hh24:mi:ss ')
from dual;
Select To_char (To_date (To_char (sysdate, ' yyyy-mm '), ' yyyy-mm '), ' Yyyy-mm-dd hh24:mi:ss ')
from dual;
--Get the start time and end time of the day before
Select To_char (To_date (To_char (sysdate-1, ' yyyy-mm-dd '), ' yyyy-mm-dd '), ' Yyyy-mm-dd hh24:mi:ss ')
from dual;
Select To_char (To_date (To_char (sysdate, ' yyyy-mm-dd '), ' yyyy-mm-dd '), ' Yyyy-mm-dd hh24:mi:ss ')
from dual;
--Get the start time and end time for the last one hours
Select To_date (To_char (sysdate, ' yyyy-mm-dd ') | | (To_char (sysdate, ' hh24 ')-1), ' Yyyy-mm-dd hh24 ')
from dual;
Select To_date (To_char (sysdate, ' yyyy-mm-dd ') | | (To_char (sysdate, ' hh24 ')), ' Yyyy-mm-dd hh24 ')
from dual;
Oracle gets this week, this month, the season, the first day of the year, and the last day