ORACLE takes the start time and end time of the week, month, quarter, and year.

Source: Internet
Author: User

 1: Obtain the start time and end time of the week.

  • Start Time of the week, starting from Monday.

SQL> SELECT TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DD HH24: MI: ss'), 'D') + 1 ASA FROM DUAL;

A

-----------

 

  • End Time of the week, ending on Sunday

SQL> SELECT TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DD HH24: MI: ss'), 'D') + 7 ASA FROM DUAL;

A

-----------

2013/12/1

 

2. Set the start time and end time of the month.
  • Start time of month

SQL> SELECT TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DD HH24: MI: ss'), 'mm') AS AFROM DUAL;

A

-----------

 

  • The end time of the month.

SQL> SELECT LAST_DAY (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DD HH24: MI: ss') AS AFROM DUAL;

A

-----------

 

3. Set the start time and end time of the season.
  • Start time of the season

SQL> SELECT TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DD HH24: MI: ss'), 'q') AS AFROM DUAL;

A

-----------

2013/10/1

 

  • End Time of the season

SQL> SELECT ADD_MONTHS (TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DDHH24: MI: ss'), 'q'), 3) -1 as a from dual;

A

-----------

 

4. Set the start time and end time of the year.
  • The start time of the year.

SQL> SELECT TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DD HH24: MI: ss'), 'yyyy') ASA FROM DUAL;

A

-----------

2013/1/1

 

  • The end time of the year.

SQL> SELECT ADD_MONTHS (TRUNC (TO_DATE ('2017-11-25 10:31:11 ', 'yyyy-MM-DDHH24: MI: ss'), 'yyyy'), 12) -1 as a from dual;

A

-----------

March 31

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.