How many weeks is the current time of the system, which is the first few weeks of this year
Copy Code code 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 every year January 1 for the first week, and date+6 for 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 the week: Date + week * 7-7 last day of the week: Date + week * 7-12)
The IW algorithm is a week from Monday to Sunday, and the first Monday of the year is the first week,
For example: 20050101 is Saturday, so using the IW algorithm is 53 weeks before the year before, and 20050103 is the beginning of the first week.
Formula: First day of the week: Next_day (date) + week * 7-7 last day of the week: Next_day (date) + week * 7-13)
Other:
A, check today is the first few weeks of "this month" SELECT 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 today is the first few weeks of "this year" select To_char (sysdate, ' WW ') from dual; or select To_char (sysdate, ' IW ') from dual;
What is the date of the week of the year:
Copy Code code 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 + "annual" + Week + "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 + "first" + Week + "Last day of the week is" + reportdateutil.getfromatday (). Format (Lastdayinweek));