Problem in getting week number

I am facing a problem regarding use of Calendar object.
I have used it to calculate Week_Of_The_Year where
the week day starts with Monday. (Mon - Sun)
Its working perfectly except the last week of this year i.e. 2004
where I want it to return fiscal week 53 , but instead its returning
1 (as because the January 1-2 ' 2005 lies in that specific week.)
and in the same manner its giving problem for the first week of the
next year i.e. 2005 .Its returning Fiscal week(FW) 2 for the
January 3-9 ' 2005 period where as I want it to return FW 1 for that
week.
here is the code snippet,
         public int getWeekNumber(String dateString) {
          Calendar cal = Calendar.getInstance();
          java.util.Date dt = new java.util.Date(dateString);
          cal.setTime(dt);
          cal.setFirstDayOfWeek(Calendar.MONDAY);
          int weekNumber = cal.get(Calendar.WEEK_OF_YEAR);
          return weekNumber;
where as date string is in mm/dd/yyyy pattern.
Please, let me know if I could clearly explain the problem to you .
I am stuck with this problem with quite some time. If anybody can crack this
problem i will be grateful.
Thanks in advance.

Haven't tried it, but have you tried playing with Calendar's setMinimalDaysInFirstWeek method? That is supposed to specify how many days must be in that first week of the year. You may need to read the Calendar API more closely.

Similar Messages

  • Query to  get  Week number  Pls help

    I need to get week number of the current year in the format 2008-W47 ( this is for sysdate
    when i try
    select to_CHAR(sysdate,'YYYY'||'-IW')
    FROM DUAL
    i get 2008-47
    but in the format 2008-W47
    Help
    s

    SQL> select to_CHAR(sysdate,'YYYY')||'-W'||to_char(sysdate,'IW') from dual
      2  /
    TO_CHAR(
    2008-W47

  • Get week number for day from a list of days within a year..

    I am beginning in ORACLE / SQL and wondering how I can use this query to work with a column of Dates that span over a number of years?
    Ideally, I would like to use this script to add a number for the week of the year based on this.
    Then when a new year begins to start over..
    I am referencing an old thread..
    TO_CHAR with dates to get week number issue
    Here is what I have so far:
    I keep getting an error stating "Bind Variable "p_date_beg" is NOT DECLARED"..
    Thanks in advance for any help you can provide.
    DECLARE
    p_date_beg DATE;
    BEGIN
    SELECT RETRIEVAL_DATE
    INTO P_DATE_BEG
    FROM OBS_SELECT_LST12_SPG;
    WITH TAB AS
    (SELECT TO_DATE(TO_CHAR(:p_date_beg,'YYYYMM')||'01','YYYYMMDD') + LEVEL -1 DATE_COL
    FROM DUAL
    CONNECT BY LEVEL <=TO_NUMBER(TO_CHAR(LAST_DAY(:p_date_beg),'DD')))
    SELECT DATE_COL, TO_CHAR(DATE_COL, 'FMDAY') DAY,
    (CASE
    WHEN TO_CHAR(TRUNC(DATE_COL, 'mm'),'FMDAY') = 'SUNDAY'
    THEN TO_NUMBER(TO_CHAR(DATE_COL,'W'))
    ELSE CEIL((TO_CHAR(SYSDATE, 'dd') + 1 - TO_CHAR(NEXT_DAY(TRUNC(SYSDATE, 'mm'), 'SUNDAY'), 'dd'))/7)
    END) WEEK_NOB
    END;

    hi, referring to this link about ISO week, http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php, here is the code:
    /* Formatted on 2012/06/13 06:32 (Formatter Plus v4.8.8) */
    WITH t AS
         (SELECT     MIN (TO_DATE ('20120101', 'rrrrmmdd') + LEVEL - 1)
                                                                       start_date,
                     1 week_th
                FROM DUAL
               WHERE TO_CHAR (  TRUNC (TO_DATE ('20120101', 'rrrrmmdd'), 'mm')
                              + LEVEL
                              - 1,
                              'FMDAY'
                             ) = 'MONDAY'
                 AND (   TO_DATE ('20120101', 'rrrrmmdd') + LEVEL - 1 <
                            TRUNC (NEXT_DAY (TO_DATE ('20120101', 'rrrrmmdd'),
                                             'THU'
                      OR (TO_DATE ('20120101', 'rrrrmmdd') + LEVEL - 1
                             BETWEEN TRUNC (NEXT_DAY (TO_DATE ('20120101',
                                                               'rrrrmmdd'
                                                      'THU'
                                 AND   TRUNC (NEXT_DAY (TO_DATE ('20120101',
                                                                 'rrrrmmdd'
                                                        'THU'
                                     + 7
          CONNECT BY LEVEL < 15),
         v AS
         (SELECT     t.start_date + 7 * (LEVEL - 1) start_date,
                     t.week_th + LEVEL - 1 week_th
                FROM t
          CONNECT BY LEVEL < 53),
         u AS
         (SELECT '20120501' dt
            FROM DUAL
          UNION ALL
          SELECT '20120502'
            FROM DUAL
          UNION ALL
          SELECT '20120503'
            FROM DUAL
          UNION ALL
          SELECT '20120504'
            FROM DUAL
          UNION ALL
          SELECT '20120505'
            FROM DUAL
          UNION ALL
          SELECT '20120506'
            FROM DUAL
          UNION ALL
          SELECT '20120507'
            FROM DUAL
          UNION ALL
          SELECT '20120508'
            FROM DUAL
          UNION ALL
          SELECT '20120509'
            FROM DUAL)
    SELECT *
      FROM u, v
    WHERE TO_DATE (u.dt, 'rrrrmmdd') BETWEEN v.start_date AND (v.start_date + 6);output:
    DT     START_DATE     WEEK_TH
    20120501     30/04/2012     18
    20120502     30/04/2012     18
    20120503     30/04/2012     18
    20120504     30/04/2012     18
    20120505     30/04/2012     18
    20120506     30/04/2012     18
    20120507     07/05/2012     19
    20120508     07/05/2012     19
    20120509     07/05/2012     19

  • Calendar to get week number of current month

    Hi All,
    Description: Currently I am working on an application which require to calculate some data for current month from a database where I have the data of all the previous and current month of that year, I can take week number as criteria.
    Help Required: I can find week of month or year using Calendar methods but how to find the first week on the current month only.
    Lets suppose the current month is April so when I use, int weekofmonth = cal.get(cal.WEEK_OF_MONTH);
    it will return me the number of present week however I want to get what would be the week number at the start of the month (April).
    Hope I am able to describe my query properly.
    Thanks in advance.
    Amit

    / ====================================================
    Method: Get the desired Date format for the date
    Developed By: Sandip Waghole [29-Jan-2010]
    ==================================================== /
    public String getWeekNo(String strDate)
    // input Date Format : M/dd/yyyy
    int weekNo=0,i=0;
    String strWeekNo=null;
    int noOfDaysInTheYear=365;
    int WEEK_STARTS_ON = 1; // Define the day on which week starts Sunday/Monday 1:Sunday 2:Monday
    int firstDayNoInFirstWeekOfPresentYear=0; // Inititalize teh day on which week is starting in present year
    int firstDayOfPresentYear=0; // Inititlize the 1st day of the present year whether Sunday/Monday/.....
    int[] monthDaysArray = {31,28,31,30,31,30,31,31,30,31,30,31}; // Define array of the days as per months
    int todaysDayNoInPresentYear=0;
    int daysLateByFirstWeekStartedAfterYearStarted=0;
    int intTemp=0;
    //strDate="08/24/2000"; // For test purpose
    StringTokenizer strDateTok = new StringTokenizer(strDate, "/ ");
    int month = Integer.parseInt(strDateTok.nextToken());
    int day= Integer.parseInt(strDateTok.nextToken());
    int year = Integer.parseInt(strDateTok.nextToken());
    GregorianCalendar cal = new GregorianCalendar();
    // Check if present year is leap year
    boolean boolIsLeapYear = cal.isLeapYear(year);
    // If it is boolean year then add 1 to total days in the year & add one more day to february
    if(boolIsLeapYear)
    noOfDaysInTheYear=noOfDaysInTheYear+1;
    monthDaysArray[1]=monthDaysArray[1]1;
    // Find the 1st day of this year
    Calendar calObj = new GregorianCalendar(year, Calendar.JANUARY, 1);
    firstDayOfPresentYear = calObj.get(Calendar.DAY_OF_WEEK);
    int intRemoveNoOfDaysFromWeek=0;
    // # Find the day no of prsent day
    for(i=0;i<month;i+) // get no of days till present year
    intTemp = intTemp monthDaysArray;
    todaysDayNoInPresentYear = intTemp - (monthDaysArray[month-1]-day);
    if(firstDayOfPresentYear==6 || firstDayOfPresentYear==7) // If first Day is Friday or Saturday then it is week
    // Identify the the day no on which 1st week of present year is starting
    firstDayNoInFirstWeekOfPresentYear = 7 - firstDayOfPresentYear WEEK_STARTS_ON 1;
    // Find delay in the 1st week start after r=the year start
    daysLateByFirstWeekStartedAfterYearStarted = firstDayNoInFirstWeekOfPresentYear - 1;
    // Now week is starting from Sunday
    weekNo = (Integer)((todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted) % 7;
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    else
    // 1st week is starting on 1st Of January
    firstDayNoInFirstWeekOfPresentYear=firstDayOfPresentYear;
    // Remove no. of days from the 1st week as week is starting from odd Sunday/Monday/Tuesday/Wednesday/Thursday
    intRemoveNoOfDaysFromWeek = 7-firstDayOfPresentYear 1; // 1 added as include start day also
    // So one week will be added in no. of weeks
    weekNo = (Integer)((todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek) % 7;
    weekNo = weekNo +1; // As 1st weeks days are reduced from the todays day no in the year
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    // Remove the no. of days from the week 1
    strWeekNo=Integer.toString(weekNo);
    return strWeekNo;
    // Any issues please mail on [email protected] or [email protected]

  • How to get week number from date

    Hi,
       please mention how to get the number of week from a particular date using fn module?

    Hi Debarshi,
                       Use FM <b>DATE_GET_WEEK</b>
    Reward points if helpful.
    Regards,
    Hemant

  • How to get week number and day in my result?

    hi experts, i have given the data is ID and DATE(yyyymmdd),i want to get output like ID,DATE,WEEKNO,YEAR,MONTH,DAY. how to get this output.
    thanks & regards
    vijay

    In a routine transformation you can call function
    DATE_GET_WEEK
    to get the week number from the date.
    To determ the others, use the substring
    YEAR = DATE(4)
    MONTH = DATE+4(2)
    DAY = DATE+6(2)

  • Get Week Number of Current Month

    How can I get the week number of the current month (1-5)?
    This is what I have tried and I'm not getting the expected
    results.

    quote:
    Originally posted by:
    DJ5MD
    Does your go 1-5 since it's only 30 days? Is that the
    difference?
    I think he was referring to your comment "How can I get the
    week number of the current month (1-5)?". Some months can have 6
    weeks so you should take that into account.
    Both the function from cflib.org and his code should return 6
    for 2007-09-30.

  • Problems with getting the number of hits in the document.

    I need to get the number of hits in the document.
    I use the query template for this porpose as:
    SELECT d.id, score(1)
    FROM document d
    WHERE contains(d.content,'<query>
    <textquery>SEARCHWORD</textquery>
    <score datatype="INTEGER" algorithm="COUNT"/></query>',1)>0
    AND d.id=1
    problems:
    1. If I have some synonyms associated with SEARCHWORD in OracleThesaurus and in case if document contains these synonyms they are not counted.
    2. could you explain the following results returned by query above:
    search query: word1 - numberOfHits=10
    search query: word2 - numberOfHits=8
    search query: word1 OR word2 - numberOfHits=10
    i suppose that numberOhHits=18 for a query: word1 OR word2

    Hi.<br><br>
    1.Synonyms (and generally thesaurus query extensions) cannot automatically uses in queries. You MUST expand you query using SYN function yourself. Query you write just applicable for only KEYWORD search.<br><br>
    2. Ask yourself. I'm not seen your data. ;)<br>
    Rgrds, Yuri.<br><br>
    PS. Just read Oracle Text Reference - you can find many answers here. ;)

  • Get week number for any given date

    How to get a week number in Java?

    / ====================================================
    Method: Get the desired Date format for the date
    Developed By: Sandip Waghole [29-Jan-2010]
    ==================================================== /
    public String getWeekNo(String strDate)
    // input Date Format : M/dd/yyyy
    int weekNo=0,i=0;
    String strWeekNo=null;
    int noOfDaysInTheYear=365;
    int WEEK_STARTS_ON = 1; // Define the day on which week starts Sunday/Monday 1:Sunday 2:Monday
    int firstDayNoInFirstWeekOfPresentYear=0; // Inititalize teh day on which week is starting in present year
    int firstDayOfPresentYear=0; // Inititlize the 1st day of the present year whether Sunday/Monday/.....
    int[] monthDaysArray = {31,28,31,30,31,30,31,31,30,31,30,31}; // Define array of the days as per months
    int todaysDayNoInPresentYear=0;
    int daysLateByFirstWeekStartedAfterYearStarted=0;
    int intTemp=0;
    //strDate="08/24/2000"; // For test purpose
    StringTokenizer strDateTok = new StringTokenizer(strDate, "/ ");
    int month = Integer.parseInt(strDateTok.nextToken());
    int day= Integer.parseInt(strDateTok.nextToken());
    int year = Integer.parseInt(strDateTok.nextToken());
    GregorianCalendar cal = new GregorianCalendar();
    // Check if present year is leap year
    boolean boolIsLeapYear = cal.isLeapYear(year);
    // If it is boolean year then add 1 to total days in the year & add one more day to february
    if(boolIsLeapYear)
    noOfDaysInTheYear=noOfDaysInTheYear+1;
    monthDaysArray[1]=monthDaysArray[1]1;
    // Find the 1st day of this year
    Calendar calObj = new GregorianCalendar(year, Calendar.JANUARY, 1);
    firstDayOfPresentYear = calObj.get(Calendar.DAY_OF_WEEK);
    int intRemoveNoOfDaysFromWeek=0;
    // # Find the day no of prsent day
    for(i=0;i<month;i+) // get no of days till present year
    intTemp = intTemp monthDaysArray;
    todaysDayNoInPresentYear = intTemp - (monthDaysArray[month-1]-day);
    if(firstDayOfPresentYear==6 || firstDayOfPresentYear==7) // If first Day is Friday or Saturday then it is week
    // Identify the the day no on which 1st week of present year is starting
    firstDayNoInFirstWeekOfPresentYear = 7 - firstDayOfPresentYear WEEK_STARTS_ON 1;
    // Find delay in the 1st week start after r=the year start
    daysLateByFirstWeekStartedAfterYearStarted = firstDayNoInFirstWeekOfPresentYear - 1;
    // Now week is starting from Sunday
    weekNo = (Integer)((todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted) % 7;
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    else
    // 1st week is starting on 1st Of January
    firstDayNoInFirstWeekOfPresentYear=firstDayOfPresentYear;
    // Remove no. of days from the 1st week as week is starting from odd Sunday/Monday/Tuesday/Wednesday/Thursday
    intRemoveNoOfDaysFromWeek = 7-firstDayOfPresentYear 1; // 1 added as include start day also
    // So one week will be added in no. of weeks
    weekNo = (Integer)((todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek) % 7;
    weekNo = weekNo +1; // As 1st weeks days are reduced from the todays day no in the year
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    // Remove the no. of days from the week 1
    strWeekNo=Integer.toString(weekNo);
    return strWeekNo;
    // Any issues please mail on [email protected]

  • ABAP Get Week Number for a Given Date.

    Hi All,
    I want to calculate week number for given date.
    SAP has provided function modules like DATE_GET_WEEK.. Etc are giving week number. taking default start day as Monday. But for my requirement is calculate week number based on start day as Sunday.
    Please let me know if we have any custom logic ??
    Thanks & Regards
    Vasu Yadav

    Hi Vasu,
    SAP standard functionality takes MONDAY as first day.
    But if you want then you can change it to SUNDAY by implementing BADI CALENDAR_DEFINITION. Create a new implementation for method IF_CALENDAR_DEFINITION~GET_FIRST_DAY_OF_WEEK and assign value as SUNDAY.
    Hope it solves your problem.
    Thanks
    Saurabh Kabra

  • Invalid redemption code problem to get serial number

    Bought adobe premiere elements 13.  Got to retrieve serial number by entering redemption code.  24 letters and numbers.  I did every way, case sensitive and not, and even the 0 with a line through it, an O or number 0?  Tried both.  Still all ways "invalid."   What now? 

    Hello Scotty,
    did you use the steps from there? >>> Redemption Code Help
    Another way, If you purchased your product from these firms like Amazon, you get this code with which you can request a serial number from Adobe. Please have a look at http://helpx.adobe.com/x-productkb/global/find-serial-number.html. (Start here: How did you purchase your product?)
    The following part, so I just see at least, ceased to exist on my Adobe website, everything takes place in the link from above. I leave it as an info yet, it might still fit for you. For this purpose, please click your way through to your Adobe Store and find the button "Get Serial Number". Fill in the form and after a while you will get the real serial number.
    Hans-Günter

  • Problem in getting serial number after BDC of IQ04.

    Hi all,
    I am doing a BDC recording of IQ04 t-code and generating serial number internally passing material number,equipment category
    and no. of serial number to be generated.
    Serial number is getting generated and i am getting BDC message 'Serial numbers generated for material xyz'.
    But my problem is i want to capture that serial number generated.
    I tried get parameter id but it is not working.
    Can anyone help me.
    Thanks,
    Nidhi.

    Its not getting capture in message table of BDC.
    This is only the problem....Because while running std transaction IQ04 also we will get only one message  'Serial numbers generated for material xyz'. So not able to capture it.
    Please suggest.
    Regards,
    Nidhi.

  • TO_CHAR with dates to get week number issue

    I am trying to build a report showing weekly sales data and running into an issue with Dates and TO_CHAR..
    Using the date 9/29/2007, I expect the return from the following to be 4:
    SELECT TO_CHAR('09/29/2007','W') FROM DUAL
    However, it returns 5!!! Testing further I tried the next day, since it is a Sunday, it should be the start of the next week, 5..
    SELECT TO_CHAR('09/30/2007','W') FROM DUAL.. I do get a 5..
    I understand that the implementation of TO_CHAR with the 'W' parameter defaults a week start on what ever the first day of the month is, but I need a method that is more calendar like (Sunday is the start of a week, Saturday end of the week).
    Anyone have a nifty solution?
    Thank you,
    Tony Miller
    UTMB/EHN

    This works pretty well. Please note that it is zero based, so add 1 if you want it to start with the first week as 1.
    WITH TAB AS
      (SELECT TO_DATE('12/01/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/02/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/03/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/04/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/05/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/06/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/07/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/08/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/09/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/29/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/30/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/31/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL)
    SELECT DATE_COL,
      TO_CHAR(DATE_COL, 'ww') W_IN_YEAR,
      TO_CHAR(TRUNC(DATE_COL, 'month'), 'ww') W1_OF_MONTH,
      TO_NUMBER(TO_CHAR(DATE_COL, 'ww')) -
      TO_NUMBER(TO_CHAR(TRUNC(DATE_COL, 'month'), 'ww')) MY_WEEK,
      TO_CHAR(DATE_COL, 'W') ORACLE_WEEK
    FROM TAB
    DATE_COL     W_IN_YEAR W1_OF_MONTH MY_WEEK  ORACLE_WEEK
    01-DEC-2007  48        48          0        1          
    02-DEC-2007  48        48          0        1          
    03-DEC-2007  49        48          1        1          
    04-DEC-2007  49        48          1        1          
    05-DEC-2007  49        48          1        1          
    06-DEC-2007  49        48          1        1          
    07-DEC-2007  49        48          1        1          
    08-DEC-2007  49        48          1        2          
    09-DEC-2007  49        48          1        2          
    29-DEC-2007  52        48          4        5          
    30-DEC-2007  52        48          4        5          
    31-DEC-2007  53        48          5        5          
    12 rows selected

  • Problem in getting spool number of a background job.

    Hi all,
    In a Z program I am calling a standard program to run as background job. I need to get the report o/p of the standard program. For this I need the spool no of the background job. Now I am querying on table tbtcp by giving jobname. Program name and run date and getting the spool no. but the cache is that the table is not getting updated with the spool no as soon as the job finishes. It is taking some time to update the table ( The time depends on the no of background jobs scheduled. ). So of we query on the table immediately after the background job finishes we are getting spool no as 0. so I am unable to read the spool into Internal tables. Even the table tsp01 is also behaving in the same way. ( it is taking time to update ) .
    Any pointers to this will be appreciated .
    Regards,
    Shiva....

    This is some prototype that I put together from separate pieces, so it looks funky, but might be helpful. The first step is to SUBMIT the program with EXPORTING LIST TO MEMORY. The next FM reads the list from memory and the next one (optional) converts it to a text format. You might want to search for other FMs in SE37 by 'LIST*'.
    DATA list_tab TYPE TABLE OF abaplist.
    SUBMIT RPR_TRIP_HEADER_DATA
    USING SELECTION-SET 'OLD_LIST'
    EXPORTING LIST TO MEMORY
                  AND RETURN.
    CALL FUNCTION 'LIST_FROM_MEMORY'
      TABLES
        listobject = list_tab
      EXCEPTIONS
        not_found  = 1
        OTHERS     = 2.
    types : t_txt(1000) type c.
    DATA: i_txt2 type table of t_txt,
    i_txt type list_string_table.
    call function 'LIST_TO_ASCI'
    EXPORTING
    *   LIST_INDEX               = -1
       WITH_LINE_BREAK          = 'X'
    IMPORTING
       LIST_STRING_ASCII        = i_txt
    *   LIST_DYN_ASCII           =
    TABLES
       LISTASCI                 =  i_txt2
       LISTOBJECT               = list_tab
    EXCEPTIONS
       EMPTY_LIST               = 1
       LIST_INDEX_INVALID       = 2
       OTHERS                   = 3
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    Also check this links:
    http://sap.ittoolbox.com/groups/technical-functional/sap-dev/spool-number-of-previously-printed-abap-list-635173#

  • How to calculate start date of the week based on week number ?

    i need to get week number of the current date and based on that i need to calculate start date falling in the same week for last year.
    Eg. today is 31st week of year and 31st july date. so what will be the date on the 31st week of last year. i need the start date of that week.
    we can calculate the week number by select to_char(sysdate,'ww') from dual.
    DO we have a single line query for that or will it require writing a pl/sql block ?

    you can try following query
    it can be as inline but for more clean look and create it as select with include select
    with t as
    (select sysdate as dt from dual)
    select to_char(prev_year_dt - to_char(prev_year_dt, 'D') + 1, 'DD.MM.YYYY') as start_of_week from (select
    -- get day from prev year with the same week number
        case
               when to_number(to_char(add_months(dt, -12), 'WW')) > to_number(to_char(dt, 'WW')) then
                dt - (to_number(to_char(add_months(dt, -12), 'WW')) - to_number(to_char(dt, 'WW'))) * 7
               when to_number(to_char(add_months(dt, -12), 'WW')) < to_number(to_char(dt, 'WW')) then
                dt + (to_number(to_char(dt, 'WW')) - to_number(to_char(add_months(dt, -12), 'WW'))) * 7
               else
                add_months(dt, -12)
           end as prev_year_dt
      from t) t1good luck
    Sergii
    'Monday' is not first day of week in 100% ;)
    Edited by: Galbarad on Jul 30, 2012 11:00 PM

Maybe you are looking for