Week of the year.

Hi,
I need a query for week of the year. i.e. if we pass the date as parameter which week the date belong.
for ex. 31-AUG-2008 then 35th week, 01-SEP-2008 then 36th week.
please help to solvel

Yes, many ways! :-)
In general built-in functionality such as the IW format on date conversion is the efficient way to do things - why reinvent the wheel? But, if your week numbers are not the standard ones (and lots of organisations run their own calendars) perhaps you could use a join to a look-up table that maps dates to week numbers.

Similar Messages

  • How to display the week of the year in a report

    Hi,
    I am doing a report, that needs to break down the information, according to month and then week.
    The week of the year isn't stored anywhere in the database, so i guess it would have to be calculated.
    How would i go about doing this in report?

    hi, yes thats what i mean.
    So if i run my report for 01-feb-2008 to 30-march-2008
    it needs to group the data according to weeks.
    eg. week5 (data)
    week6 (data)
    etc....
    i got this code: select to_char(sysdate, 'IW') from dual;
    will it allow me to do this?

  • Week of the year number appears out of sync with the day of week the week #

    Using the querry below on on a table where the pdate value is a sequential list of dates on an Oracle 11 database the results show the week of the year number changes on the day of the week number 7 not the day of the week number 1. Is there a patch to fix this?
    select
    pdate,
    to_char(pdate,'D') dow,
    to_char(pdate,'Day') Day_name,
    to_char(pdate,'WW') week_of_the_Year
    from daily_period_tab
    where pdate >= '07-jan-11'
    and pdate <= '09-jan-11'
    07-JAN-11     6     Friday      01
    08-JAN-11     7     Saturday      02
    09-JAN-11     1     Sunday      02

    Hi,
    Independent of you NLS settings, you can do this:
    SELECT     TRUNC ( dt + 1
               , 'IW'
               ) - 1     AS sunday
    FROM     table_x;The output in the sunday column will be the Sunday on or before dt. The "magic number" 1 indicates that your week starts 1 day before the ISO week, which starts on Monday.
    Or if you want to use your NLS settings:
    ALTER SESSION     SET NLS_TERRITORY= 'AMERICA';
    SELECT     TRUNC ( dt
               , 'DY'
               )          AS sunday
    FROM    table_x; 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Problem in getting exact week of the year (Reposted)

    Hi,
    Can somebody respond to my posting please. I am posting it second time since nobody replied me till yet.
    I make use of below code to get exact week of the year.
    // Assumes the provided date is in 'ddMMM' format
    SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMM" );
    Date parsedDate = sdf.parse( dateString );
    Calendar calendar = Calendar.getInstance();
    calendar.setTime( parsedDate );
    int week = calendar.get( Calendar.WEEK_OF_YEAR );
    Problem which I am facing is that when I pass "dateString" as
    "22Mar" then it gives week as 13 instead of 12 for year 2007.
    I find out that making use of cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ); statement eradicates the problem, ideally values should be
    cal.setFirstDayOfWeek( Calendar.SUNDAY); and cal.setMinimalDaysInFirstWeek( 7); because for US first day of the week should be SUNDAY and minimum number of days should be 7 when I start from Sunday.
    Please help me to understand the resolution. Is it correct or not?
    Is it possible to solve the problem without specifying cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ).
    This seems to be hardcoded for each year.

    What am I missing? If you can't accept the ISO rules then you are going to define and implement your own algorithm. UsingSimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
            Date parsedDate = sdf.parse( "2007/01/01" );
            Calendar calendar = Calendar.getInstance();
            calendar.setFirstDayOfWeek(Calendar.MONDAY);
            calendar.setTime( parsedDate );
            for (int count = 0; count < 366; count++)
                int week = calendar.get( Calendar.WEEK_OF_YEAR );
                System.out.println(week + "\t" + sdf.format(calendar.getTime()));
                calendar.add(Calendar.DAY_OF_YEAR, 1);
            }I get the week as 12 not 13 but I specified THIS year. If you don't specify a year then, quite rightly, it takes 1970.

  • Problem in getting exact week of the year

    Hi,
    I have make of use of below code to get exact week of the year.
    Now problem which I am facing is that when I pass "dateString" as
    "22Mar" then it gives week as 13 instead of 12 for year 2007.
    // Assumes the provided date is in 'ddMMM' format
    SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMM" );
    Date parsedDate = sdf.parse( dateString );
    Calendar calendar = Calendar.getInstance();
    calendar.setTime( parsedDate );
    int week = calendar.get( Calendar.WEEK_OF_YEAR );
    I find out that making use of cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ); statement eradicates the problem, ideally values should be
    cal.setFirstDayOfWeek( Calendar.SUNDAY); and cal.setMinimalDaysInFirstWeek( 7); because for US first day of the week should be SUNDAY and minimum number of days should be 7 when I start from Sunday.
    Please help me out to understand the resolution. Is it correct or not?
    Is it possible to solve the problem without specifying cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ). This seems to be hardcoded for each year.
    Thanks in advance...

    What am I missing? If you can't accept the ISO rules then you are going to define and implement your own algorithm. UsingSimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
            Date parsedDate = sdf.parse( "2007/01/01" );
            Calendar calendar = Calendar.getInstance();
            calendar.setFirstDayOfWeek(Calendar.MONDAY);
            calendar.setTime( parsedDate );
            for (int count = 0; count < 366; count++)
                int week = calendar.get( Calendar.WEEK_OF_YEAR );
                System.out.println(week + "\t" + sdf.format(calendar.getTime()));
                calendar.add(Calendar.DAY_OF_YEAR, 1);
            }I get the week as 12 not 13 but I specified THIS year. If you don't specify a year then, quite rightly, it takes 1970.

  • Convert date to week of the year in Query designer

    Hi,
    I have a requirement to convert date ( a characteristic in the query) to week of the year. For eg. if the date is 01/11/2008 then the week to be displayed is 2008/44.
    Please not that the week is not populated in the Infocube of the same. So i need to convert it in the query designer only.
    Please suggest if you have ideas.
    Regards
    Sapna

    Hi,
    I am trying to get the data by using a virtual characteristic. The problem is i am not able to debug METHOD : IF_EX_RSR_OLAP_BADI~COMPUTE. Can u please help me to reach the breakpoint within this.
    Done....
    Sapna
    Edited by: Sapna Jaiswal on Dec 2, 2008 11:21 AM

  • Converting "01Jan2008" to week in the year

    Is there a function in Microsoft Excel to convert a date to a week in the year ? I know this is an Oracle site but I figure there is overlap.

    Is there a function in Microsoft Excel to convert a
    date to a week in the year ? I know this is an Oracle
    site but I figure there is overlap.You figure there's an overlap between a relational database and a spreadsheet? If you had said there was an overlap between Oracle and Access I could see where you're coming from but not Oracle and Excel.
    Anyway here's the help from MS Excel...
    WEEKNUM
    Returns a number that indicates where the week falls numerically within a year.
    If this function is not available, and returns the #NAME? error, install and load the Analysis ToolPak add-in.
    How?
    On the Tools menu, click Add-Ins.
    In the Add-Ins available list, select the Analysis ToolPak box, and then click OK.
    If necessary, follow the instructions in the setup program.
    Syntax
    WEEKNUM(serial_num,return_type)
    Serial_num   is a date within the week. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.
    Return_type   is a number that determines on which day the week begins. The default is 1.
    Serial_num Week Begins
    1 Week begins on Sunday. Weekdays are numbered 1 through 7.
    2 Week begins on Monday. Weekdays are numbered 1 through 7.

  • How get the number of some week in the year

    such as:
    1/1/2002 is 1
    1/7/2002 is 2
    1/21/2002 is 4

    hi, you can do it using the field "WEEK_OF_YEAR" of class java.util.calendar.
    such as:
    Calendar calendar = Calendar.getInstance();
    int weekNumber = calendar.get(WEEK_OF_YEAR );

  • XSLT Mapping: how to calculate Week number of the year from given date

    Hi,
    I  have input as date, i need to know the Week number from that date in XSLT Coding.
    for Eg: if date is 29-12-2009 it should give 53rd week of the year.
    All answers will be appreciated.
    Regards,
    Mayank

    Hi add this statement to your XSLT Mappping
    <xsl:stylesheet version="1.0" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="java">
    and use <xsl:template name="GetDateInLocal" xmlns:cal="xalan://java.util.GregorianCalendar"> in XSLT Mapping , write your logic.
    cheers,
    Raj

  • How to get week of a year in American Standard

    Hi,
    I know it might be a repetitive question, but did not find a convincing solution to it in any of the previous threads. I am looking for a function (user defined, if someone has already written it) to return me the week of the year, in American Standard. i.e,the week should start on Sunday and end on Saturday (and NOT from Monday to Sunday)
    01/03/2010 - Should be the start of 1st week of 2010...... 01/10/2010 will be the start of second week and so on
    01/04/2009 - Should be the start of 1st week of 2009...... 01/11/2009 will be the start of second week and so on.
    Does any one have a function that takes a date as input and returns back the week of the year in this above format? Any help is greatly appreciated.
    Thanks

    It's a bit trickier because the ISO rule has some fine prints.
    Take a look at the example below:
    SQL> with t as (
      2  select to_date('01/02/2010', 'MM/DD/YYYY') dt from dual union all
      3  select to_date('01/03/2010', 'MM/DD/YYYY') dt from dual union all
      4  select to_date('01/03/2009', 'MM/DD/YYYY') dt from dual union all
      5  select to_date('01/04/2009', 'MM/DD/YYYY') from dual)
      6  --
      7  select dt,
      8         to_char(dt+1, 'iw') tweaked_week,
      9         to_char(dt, 'ww') nls_week
    10    from t
    11   order by dt;
    DT          TWEAKED_WEEK NLS_WEEK
    3/1/2009    01           01
    4/1/2009    02           01
    2/1/2010    53           01
    3/1/2010    01           01
    SQL> If may notice that 02/01/2010 is week 53 and and that at the same time 03/01/2009 is already week 1, being 04/01/2009 week 2.
    The reason is in the docs:
    An ISO week always starts on a Monday and ends on a Sunday.
    * If January 1 falls on a Friday, Saturday, or Sunday, then the ISO week that includes January 1 is the last week of the previous year, because most of the days in the week belong to the previous year.
    * If January 1 falls on a Monday, Tuesday, Wednesday, or Thursday, then the ISO week is the first week of the new year, because most of the days in the week belong to the new year.It depends on what your requirement asks.
    If you need to prevent any January 1st that fall on Monday to Thursday from becoming your week 1 you'd probably have to adjust that implementation and fine tune it further.
    Let us know if that will do or what your rule would be otherwise.

  • How to find first day of the year

    Big picture: trying to determine how many pay periods are left in the year. There are 52 weeks in a year, and our company pay out each week.
    The first pay week of the year always starts on a Friday. So If Janurary 1 is a friday, then the 1st week of pay period starts that week. If Jan 1 is a Thursday, then the first pay week will start on Janurary 2.
    I need to figure out what day the first day of any year it is. By day, i mean Mon, Tue, Wed, Thur, Fri, Sat, or Sun.
    Then when I figure out what day it is, i will write an if/then statement saying if Jan 1 is a monday, then add 4 days to that date and that will be the first day of a pay period.
    Then when i figure out the first day of the first week, I wanted to add 7 days to create week2, week3.... week 52.
    Then take todays date and if it was between week x and week y, then it would determine that z many pay periods are left...
    is this the best way to go about this? anything easier?

    You can use the getDay method of a Date object to determine the day of the week. Any decent JavaScript reference will have more information.
    George

  • FM for week in a year

    is there any FM for
    how many weeks in a year and
    how to find the whether the year is leap year or not? and
    how many weeks are in the month ?
    i want the FM

    Hi there. You can use function module hr_99s_interval_between_dates.  Just pass a begin date and an end date, and then you can get the number of days, weeks, months, or years between the two dates.  So you can pass the begin date and end date of a month to get the number of weeks in the month, or the begin date and end date of a year to get the number of days and weeks in the year.  If the number of days is 366 then it is a leap year.  I hope this helps.
    - April King
    Message was edited by:
            April King

  • HT201412 I cannot open the month of March 2013 in my iPad3 calendar. I can however see it in the year view for 2013 and I can view the daily and weekly calendars for March 2013. Any ideas what has gone wrong ? Thanks

    I have a new iPad3 and have found I cannot open the month of March 2013 when I tap on it. All other months open OK ! I can see March 2013 in the yearly view and I can open the individual days, and weeks, of March 2013 but I cannot see the whole month in the monthly view. When I try to open the monthly view for March 2013 it returns me to the start screen which shows all the apps etc and closes the Calendar app. Any guidance of what is going wrong and how it can be corrected. Thanks !

    Don't worry we have to start somewhere. Feel free to post your questions here, we learn from each other.

  • FM to find the number of fiscal weeks in a year

    Hi All,
    Can anyone pls give me the  function module to find the number of fiscal weeks in the given year.
    Thanks,
    Rajani.

    Eric Cartman wrote:
    Ámit Güjärgoüd wrote:
    > > Eric,
    > >
    > > Did you actually enjoy 2004 ?
    wasn't bad...
    do you mean, there were 53 weeks in that year? because I have concern, how it is actually counted...
    wasn't bad... :)
    Thats sounds Sweet
    do you mean, there were 53 weeks in that year?
    Yes
    because I have concern, how it is actually counted...
    If in a leap year fabruary falls in 5 weeks then that is the only possibility for 53 weeks
    Cheers
    PS:But No logic would be applied in this case

  • How to get the week number of year from a Date object?

    Hi!
    I would like to know the week number of the year from a specified Date.
    I dont know how to set the first day of week, and set the minimum days of a week.
    I want to use Monday for first day of week, and at least 4 days of month in a week.
    For example if its 1st, January is Friday, then the first week starts on 4th, Monday.
    Anyone can help?

    Sorry. I should think before I move.
         public static int getWeekOfYear(Date date) {
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(date);
             calendar.setFirstDayOfWeek(Calendar.MONDAY);
             calendar.setMinimalDaysInFirstWeek(4);
             return calendar.get(Calendar.WEEK_OF_YEAR);
         }

Maybe you are looking for

  • Discoverer Report Requirements

    Hi I am fairly new to Portal and currently looking at implementing it for a client using Portal v 10.1.4.1 and AS 11.5.10.2. Currently I am gathering requirements and one of these is to allow the users to display a number of Discoverer reports. At pr

  • Get CD Info from Music Manager no longer available

    After upgrading PC Suite to 6.82.22 the option to "Get CD information" from Gracenote has been removed, or at least in my case it is no longer available. However, when looking at the help files, it still appears to give directions on how to use this

  • Account Assignment Category K in KOB2

    Hello, A purchase order with account assignment category K (Cost center) appears in the commitment line items for orders list (KOB2) while there is no relation between the shown internal order and the purchase order/requisition. Regards, Jan

  • Custom datagrid headerRenderer keeps redrawing

    I have two DataGrids.  One that uses default headerRenderers, and one that uses custom 'filterable' headerRenders for 5 of the column headers. Basically, the custom filterable headerRenderer is a VBox that holds a Label and a TextInput.  Typing in th

  • ORA-01000: maximum open cursors exceeded ORA-06512

    Hi, An exception error ccurred as below while trying to map a column. Exception oracle.apps.bne.exception.BneSQLException: SQL Exception in BneFlex.validateSegs: java.sql.SQLException: ORA-01000: maximum open cursors exceeded ORA-06512: at "APPS.FND_