Oracle View the current date is the first few weeks of the method _oracle

Source: Internet
Author: User
Tags current time
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));
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.