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 ));