Oracle date converted to weeks, months, quarters, half-yearly, year

Source: Internet
Author: User

To achieve the current time, week, month, quarter, half year, years of conversion, where special attention is to the processing of the week, the IW way of handling logic, if this week has greater than or equal to 4 days, this week belongs to a few years, if less than 4 days, this week belongs to the next year

In 1990/12/31, for example, this day belongs to 199,101 weeks.

SELECT To_number (To_char (sysdate, ' YYYYMMDD ')) as PERIOD,
Sysdate as P_date,
To_number (To_char (sysdate, ' Iyyyiw ')) as P_week,
To_number (To_char (sysdate, ' YYYY ') | | To_char (sysdate, ' MM ')) as P_month,
To_number (To_char (sysdate, ' YYYY ') | | To_char (sysdate, ' Q ')) as P_quarter,
Case
When To_char (sysdate, ' MM ') >= 7 Then
To_number (To_char (sysdate, ' YYYY ') | | ' 2 ')
ELSE
To_number (To_char (sysdate, ' YYYY ') | | ' 1 ')
END as P_half_year,
To_number (To_char (sysdate, ' YYYY ')) as P_year,
Sysdate last_modify_date
From DUAL T

Oracle date converted to weeks, months, quarters, half-yearly, year

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.