Oracle viewing date is the week

Source: Internet
Author: User

In oracle, check the week number of the system. The week number of the year is www.2cto.com select to_char (sysdate, 'ww '), to_char (sysdate, 'iw ') from dual; select to_char (sysdate, 'ddd ') from dual; select TRUNC (SYSDATE, 'mm') from dual; 1) The ww algorithm starts from the first week every year on January 1, January 1, date + 6 is the end of each week. For example, 20050101 is the first day of the first week, and the last day of the first week is 20050101 + 6 = 20050107 formula: the first day of each week: date + week * 7-7 last day of each week: date + week * 7-12) the iw algorithm calculates a week from Monday to Sunday, and the first Monday of each year is the first week, for example, 20050101 is Saturday, so the iw algorithm is 53 weeks of the year before, and 20050103 The beginning of the first week. Formula: First day of each week: next_day (date) + week * 7-7 last day of each week: next_day (date) + week * 7-13) www.2cto.com others: a. Check the week when "this month" is selected TO_CHAR (SYSDATE, 'ww ')-TO_CHAR (TRUNC (SYSDATE, 'mm'), 'ww ') + 1 AS "weekOfMon" from dual; or SELECT TO_CHAR (SYSDATE, 'w') AS "weekOfMon" from dual; b. Check the week number of this year for select to_char (sysdate, 'ww ') from dual; or select to_char (sysdate, 'iw') from dual; count the day of the week of the year: int year = 2011; int week = 1; Calendar calFirstDayOfTheYear = new GregorianCalendar (year, Calendar. JANUARY, 1); calFirstDayOfTheYear. add (Calendar. DATE, 7 * (week-1); int dayOfWeek = calFirstDayOfTheYear. get (Calendar. DAY_OF_WEEK); Calendar calFirstDayInWeek = (Calendar) calFirstDayOfTheYear. clone (); calFirstDayInWeek. add (Calendar. DATE, calFirstDayOfTheYear. getActualMinimum (Calendar. DAY_OF_WEEK)-dayOfWeek); Date firstDayInWeek = calFirstDayInWeek. getTime (); System. out. println (the first day of year + "year" + week + "week is" + ReportDateUtil. getFromatDay (). format (firstDayInWeek); Calendar calLastDayInWeek = (Calendar) calFirstDayOfTheYear. clone (); calLastDayInWeek. add (Calendar. DATE, calFirstDayOfTheYear. getActualMaximum (Calendar. DAY_OF_WEEK)-dayOfWeek); Date lastDayInWeek = calLastDayInWeek. getTime (); System. out. println (the last day of week year + "year" + week + "is" + ReportDateUtil. getFromatDay (). format (lastDayInWeek ));

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.