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.

Similar Messages

  • 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]

  • Rollover 18 weeks starting from week number of current month

    Hi,
    I have a requirement as described below.
    Table Name Time:
    Columns: Fiscal Year, Fiscal Month and Fiscal Week
    above table has join with sales table and it contain sales data on week basis. so least granularity of data at week level.
    we have a report with columns fiscal year, actual sales and forcast sales. our requirement is to filter the data with following criteria.
    Current Month Filter
    Jan fiscal week between 1-18 of current year
    Feb fiscal week between 5-23 of current year
    March fiscal week between 9-27 of current year
    November fiscal week between week 44 of current year and week 10 of next year
    December
    so with above requirement we need to filter data with rollover 18 weeks starting from week number of current month
    I tried with timestampadd(sql_tsi_week, interval, week) but it's not working as I expacting. Please provide the code/logic to get it done.
    Appreciate your help.
    Thanks
    Jay.

    Jay wrote:
    I need to get rollover 18 week data at anypoint of time starting with week number of 1st of every month to 18 weeks. read my question again and you will be able to understand.You're kind of missing the point to be honest. It's very hard to answer specific questions without the required information. To answer a question like this we need a minimum of:
    1. Oracle version
    2. Sample data (CREATE TABLE / INSERT statements)
    3. Expected output
    4. Explanation of business rules.
    Alternatively, you can read the link in my original response.
    Please provide the required information and someone can help.

  • How to get week of the current month

    Hi all,
    Is there any way to find out week of the current month.
    Please help..

    Do not confuse date format and the parameter in the file NqsConfig.ini
    http://gerardnico.com/wiki/dat/obiee/bi_server/nqsconfig
    As say in the previous link, you must check in the NqsCOnfig.ini file that you have this line
    DATE_TIME_DISPLAY_FORMAT = "yyyy/mm/dd hh:mi:ss" ;because the cast function take it as format to discover the day, month and year.
    Besides, the functions WEEK_OF_YEAR AND MONTH don't care about the date format, they only need a date.
    Check here this article :
    http://gerardnico.com/wiki/ide/toad/toad_date_format
    To see that the date format is much more a question of rendering (for OBIEE, Toad or SqlPlus) than of data.
    Verify your NqsConfig.ini and give a try.
    Success
    Nico

  • Derive week number of that month

    Hi,
    I need to derive week number based on month.
    Ex:
    Sy-datum = 10.10.2010
    Month: 10.2010
    Calweek: 40.2010
    Week no: 2
    Sy-datum = 11.10.2010
    Month: 10.2010
    Calweek: 41.2010
    Week no: 3
    So for everymonth I need to store the week no in the cube
    Ex
    Date--Month--
    calweek............weekno
    10.10.2010.............10.2010.............40.2010...............2
    10.10.2010.............10.2010.............40.2010...............2
    10.10.2010.............10.2010.............40.2010...............2
    11.10.2010.............10.2010.............41.2010...............3
    11.10.2010.............10.2010.............41.2010...............3
    11.10.2010.............10.2010.............41.2010...............3
    So here i need to derive week number for a date in the month
    Can anyone please help what logic to be applied to get the week number?
    Thanks
    Annie
    Edited by: Annie on Oct 14, 2010 7:48 AM

    Hi Annie, I'm not very sure of any function modules, but you may try this logic:
    1. Date Format Stored in SAP: YYYYMMDD.
    2. Use a formula X+6(2) to get the DD part.
    3. Use Conversion Exit  'CONVERSION_EXIT_ALPHA_INPUT'
    4. Logic: [ DATUM's DD ] MOD 7 which gives the week # ordering for the particular month.
    5. Close the START Routine passing the temp value to RESULT.
    DATA:var_dd type sy-datum, var_temp(2) type i.
    var_dd = SOURCE_FIELDS-ZDATE+6(2).
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
            EXPORTING
              INPUT  = var_dd
            IMPORTING
              OUTPUT = var_dd.
    if sy-subrc = 0.
    var_temp = var_dd MOD 7.
    end if.
    RESULT = var_temp.
    Pls. review & let me know your comments.
    Thanks.
    Edited by: Arun Bala G on Oct 14, 2010 12:22 PM

  • 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

  • IPCC 7 Determine the week number of a month

    Hello,
    I am working towards determine the week number of month and make appropriate routing changes only for that specific week. I have tried using the trunc(), getdate() and weekday(). But i fail to get the week number of a month, but I believe I have managed to the week number of a year.
    The example I have considered is: On Tuesday and Thursdays in second week of every month the calls to be routed to a different skillgroup.
    Please let me know if anyone has any suggestion for this.
    Thanks,
    FYI,
    CM 4.1, CRS 3.5, ICM 7.1

    Hi buddy,
    Great stuff!! Your link gave me another hint of the possible solution, I was working on ICM but not sure why i did not consider CRS for this requirement , The CRS has a builtin function, I have used this builtin Methods which provided me what i expected.
    The debug on the script resulted the week of the month for today which is "4".
    Please let me know your view.
    Thanks again!

  • Report for getting an oppotunity for current month

    Please tell what can be a filter or function for getting an oppotunity for current month , i have the field as "Opportunity created date" so what function or SQL expression can b eused to get created date = current month's date

    Thanks..i'll do taht
    Edited by: user1074008 on Sep 28, 2010 3:11 AM

  • How to get the number of current active external modes?

    hi all,
    I need to get the number of currently active external modes. This can be done by calling function THUSRINFO. But this only works propperly, if you are logged on only once. If you are logged on more than one time then the function returns several entries in the parameter USR_TABLE. The entries mainly differ in the first parameter TID (type UTID, INT4) "terminal-identification" but how can I know which is the valid one for my current session. Functions TERMINAL_ID_GET, SPH_TERMINAL_IDENTIFY and SPH_TERMINAL_ID_GET dont work.
    Or is there another way to get the number of active external sessions?
    Thanks in advance,
    Michael

    Hi,
    tables: usr02, usr41.
    data: OPCODE_MODE_COUNT(1) TYPE X VALUE 3,
          modes like sy-index,
          u_MODES LIKE MODES.
    select * from usr02.
      select * from usr41 where BNAME = usr02-bname.
        CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE_MODE_COUNT
          ID 'TID' FIELD usr41-TERMID
          ID 'MODES' FIELD MODES.
        IF SY-SUBRC = 0.
          u_MODES = u_MODES + MODES.
        ENDIF.
      endselect.
      if sy-subrc = 0.
        write:/ usr02-bname, u_MODES.
      endif.
      clear u_modes.
    endselect.

  • 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

  • TO GET WEEKS for a given MONTH AND YEAR

    Is there any FM to get the no of weeks for a given month, say 01 2005.
    Can i get the week numbers say 1 2 3 4 5 for the given month and year.
    Please let me know.
    Happy Holidays.
    Regards,
    Manohar E

    Hi Manohar,
       Use FM DATE_GET_WEEK twice; first time pass first day of the month and again pass the last day of the month as a parameter. So u will be having week number(yyyyxx) for the first week of the month and week number for the last week of the month. From these two, in between week numbers u can easily fetch. I hope this will help u out.
    Regards,
    Kavya Shah

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

  • How to get the number of years, months with two sysdate()

    Hi All,
    Sorry for posted another question regarding the conversion.
    I have the hiring day and current day in date format like : '2005-10-01' and '2006-09-14'
    How to get the differences between current date is ('2006-09-01') and
    hiring date is ('2004-10-01' )
    in the format number of years and number of month without using the Mod
    function . For this example the result is : 2 years 1 month
    Thanks
    JP

    How to get the differences between current date is ('2006-09-01') and
    hiring date is ('2004-10-01' )
    in the format number of years and number of month without using the Mod
    function . For this example the result is : 2 years 1 monthshould not it be 1 year 11 months???
    SQL> select (date '2006-09-01' - date '2004-10-01') year to month diff from dual;
    DIFF
    +01-11

  • 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]

  • 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

Maybe you are looking for

  • Logo Windows Live

    Hello All, Perhaps someone can help me with this problem. I have a N95 and uninstalled recently Windows Live. In 'messaging' there is still a Windows Live logo ( with a question mark in front of it ). How can i remove / uninstall this logo? See attac

  • How to see an explain plan?

    Hi all, I'm looking to tune one sql sentence of my application. To do it, I've used the sqltune package. When I see the report, I obtain the actual explain plan and, finally the suggestion to use an SQL Profile. How can I see the new explain plan of

  • As-built in smartforms

    Hello! I create a report with materials in smartforms. Those of materials that are connected with as-built I can't unload into my report. Other works good. How can I solve this problem? Regards, Alexander.

  • Copy and Paste a Workflow

    I would like to copy a workflow I created on my testing site and paste the workflow in to my production environment. I really don't want to rewrite the entire workflow over again in production.

  • SEM-BCS Flatfile Breakdown

    Hello to you all, after I set up BCS 6.0 and activated the content I had to fix some problems and there are still some. This is one of them: I need to upload the "account types" and the Flatfile has text instead of numbers for the types (e.g. "possib