Oracle gets this week, this month, the season, the first day of the year, and the last day

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.