How to view the current date in oracle

Source: Internet
Author: User
The code segment for oracle to check whether the current date is the week method. For more information, see

The code segment for oracle to check whether the current date is the week method. For more information, see

The current system time is the week of the year.
The Code is as follows:
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 on January 1, January 1 each year, and 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: 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 is 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)

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 year and week:
The Code is as follows:
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 (year + "year" + week + "the first day of the 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 (year + "" + week + "the last day of the week is" + ReportDateUtil. getFromatDay (). format (lastDayInWeek ));

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.