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

Similar Messages

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

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

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

  • Best method to determine the week number of a month - SQL Server 2012

    Hi,
    I'm searching the most valid and tested method to determine the week number respect to a month.
    Fe, the 1st January falls in the 1st week of January, the 1st February fall in the 1st week of February, and so on.
    I've found many solutions but I'd like to know possibly the best one.
    Thanks

    Hi Uri,
    SELECT DATEPART(week, '20150104')
         - DATEPART(week, CONVERT(CHAR(6), '20150104', 112)+'01')
         + 1
    returns 2 and not 1. It's a Sunday.
    Waiting to be spoonfed, eh?
    The one-off in my query would be very simple to figure out - I forgot to add the +1. Is too much to expect from you that you could figure it out yourself?
    And likewise, in my post I said that you should use "week" for weeks starting on Sunday, and "iso_week" if your week starts on Monday. Uri neglected to observe this, but you had the information to correct it. If you had been interested
    in doing some work yourself, that is.
    Nevertheless, there is an issue that I overlooked:
    DECLARE @day date = '20160105'
    SELECT datepart(iso_week, @day) -
           datepart(iso_week, convert(char(6), @day, 112) + '01') + 1
    This returns -51. This is because with ISO week numbering, Jan 1st falls into week 53 of the previous year, if it's on a Friday or later. Week 1 is always the week of Jan 4th. When you week this does not happen, as week 1 is always the week with Jan
    1st. (Dec 31st is always in week 53 or 54.)
    To correct for this, we need this query:
    SELECT DATEPART(iso_week, @day) -
           CASE WHEN DATEPART(iso_week, CONVERT(CHAR(6), @day, 112) + '01') < 50
                THEN DATEPART(iso_week, CONVERT(CHAR(6), @day, 112) + '01')
                ELSE 1
           END + 1
    Erland Sommarskog, SQL Server MVP, [email protected]

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

  • Return date for a given week number in a month

    Hi,
    Can someone urgently post a snippet code that will return the date if the week number and the weekday (like wednesday) for a given month in an year is passed.
    ex: If I say 2nd wednesday of August in 2004 , it must return the date for second wednesday. URGENT

    Don't flag your question as urgent, even if it is for you. Claiming urgency is very likely to be counter-productive: most forum regulars will simply ignore such messages as rude and selfish attempts to elicit immediate and special attention.
    Besides, unless the Symbionese Liberation Army is about to chase you over the edge of a cliff, your problem probably isn't as urgent as you think. :o)

  • FM for week number of month

    Hi all,
       Could you suggest me a FM for for finding the week number of a month.
       I can see FM which shows week number of an year .But i want the week number with reference to a month.
    Thanks
    Sam.

    Hi,
    A sample using function DATE_GET_WEEK 
    Report try05.
    DATA: xweek(6)    TYPE n,
                        xdt      TYPE d.
    xdt = '20050101'.
    CALL FUNCTION 'DATE_GET_WEEK'
      EXPORTING
        DATE               = xdt
    IMPORTING
       WEEK               = xweek
    EXCEPTIONS
       DATE_INVALID       = 1
      OTHERS             = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    WRITE:/ xdt.
    WRITE:/ xweek.
    Hope this helps.
    Reward if helpful.
    Regards,
    Sipra

  • 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

  • Dreamweaver MX extracting week number

    My form collects a date (which the user picks from a pop-up
    calendar). That date is submitted to a field (datBegin) in the
    MySQL database. Fine.
    In the process of submitting that date, I want a portion of
    it (the "week-number" represented by the date that the user
    entered) to be submitted to another field (week_nbr) in the same
    MySQL database and table.
    In other words, the user enters the date once. When he clicks
    submit, the date (like 2007-5-17) is placed in the datBegin field,
    and the week number (like 20) should be placed in the week_nbr
    field.
    The formating of the week number is not a problem. It is done
    with DATE_FORMAT(datBegin,'%u'). But the submitting of it to the
    database is what I am not able to accomplish. The date and the week
    number are of course part of the same record (row).
    If anyone can help, I'd greatly appreciate it. (I have run
    out of things to try!) Most of my attempts have been to create a
    value for week_nbr in a hidden field. I have also tried the
    DATE_FORMAT in Recordsets. None of this has been succesful in
    getting a week_nbr value (based on the just entered datBegin)
    stored to the MySQL database.
    I use PHP and work with Dreamweaver MX.

    Hi David Powers,
    Thanks for your input regarding the week number problem.
    re.
    > The way to do it is to use
    DATE_FORMAT(datBegin,'%u') as part of your query. For
    example:
    SELECT thisCol, thatCol, DATE_FORMAT(datBegin,'%u') as
    week_num
    FROM mytable
    ORDER BY week_num DESC
    This is exactly what I have tried over and over again, many
    times. This
    approach fails when you add the WHERE statement:
    WHERE kalendar.week_nbr = servicegrupp.vecka
    However, when I hard code the week_nbr into the kalendar
    table, then the
    WHERE statement works as intended. There is a match, in other
    words.
    It appears that the reason it does not work unless the
    week_nbr is in the
    table, is that "week_num" (as you have it) from the query is
    not a field but
    something else, perhaps a variable. I'm not sure about the
    terminology. To
    match output from the table with output from an AS statement
    in the query
    does not work -- at least not in my experience.
    I guess the scenario is one of relations. In other words the
    "week_nbr"
    from the kalendar table relates to the "vecka" in the
    servicegrupp table.
    When both are present in their respective tables, the match
    occurs.
    To try to match them at the output stage, using the AS
    statement in the
    query, does not work. The wrong "week_nbr" is inserted --
    always the number
    from the top record in the table, it appears.
    I know that in the case of relational tables, it is possible
    to output the
    id from one table to the foreign key in the related table. It
    is this
    facility I need to find, somehow, even though I am not
    dealing with the ids.
    These are my reasonings at the moment. But there is probably
    a better, more
    elegant way to accomplish the needed match.
    Thanks again for your willingness to help.
    Curt L. Gustafsson
    ----- Original Message -----
    From: [email protected]
    To: [email protected]
    Sent: Thursday, May 31, 2007 7:31 PM
    Subject: Dreamweaver Support subscription update.
    Newsgroup User has posted a message entitled Re: Dreamweaver
    MX extracting
    week number.
    Message Posted on: Thursday May 31,2007 10:31:12 AM
    curtgus wrote:
    > In the process of submitting that date, I want a portion
    of it (the
    > "week-number" represented by the date that the user
    entered) to be
    submitted to
    > another field (week_nbr) in the same MySQL database and
    table.
    You don't need to. The information stored in datBegin already
    contains
    that information, as you point out yourself.
    > The formating of the week number is not a problem. It is
    done with
    > DATE_FORMAT(datBegin,'%u').
    You're approaching the problem the wrong way. You presumably
    want to
    store the week number so that you can search according to
    week number or
    display results by week number. The way to do it is to use
    DATE_FORMAT(datBegin,'%u') as part of your query. For
    example:
    SELECT thisCol, thatCol, DATE_FORMAT(datBegin,'%u') as
    week_num
    FROM mytable
    ORDER BY week_num DESC
    David Powers, Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/
    You can view the message at
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?catid=189&threadid=1272474&fo rumid=12.

  • How do I set twice monthly events based on the week number

    Greetings all. I can't seem to navigate this help system, so hopefully I'm not reasking something that's already been asked. But I have a problem with iCal that I just can't figure out of find an answer to. I need to create a twice monthly event, but it's based on the week number, not every two weeks. For example, I need to be able to create an event for the 2nd and 4th Mondays of the month. Is that possible with iCal? Thanks for your help... and not laughing at me
    Steve

    No problem.
    Go to Monday select the day you want. Create new Event. Then select repeat and you will come up with how you want to repeate it. Select Monthly and then do the following:

  • How to determine the month from the week number?

    Hi all,
    in a routine i have the week number in a year and i need to find the month but i don't know the correct FM to use for this.
    Is there anyone that had to face a similar problem?
    I'm considering that to determine the month it will be used the first day of the week since there are weeks belonging to 2 different months...
    Thank you
    Stefano

    Hi
    If you have a Fiscal Year Variant determined for the week you can use function module PERIOD_DAY_DETERMINE by passing week,fiscal year and fiscal year variant for the week which will return fist and last date.So based on last data you can determine the month.
    Regards
    Srilaxmi

  • How do I look for a date that corresponds to a particular Week Number in a table?

    Hello,
    I have a table (Table A) that looks like this (I am only including the first 5 months to keep image size down):
    The numbers in the table are dates, with custom formatting to just show the day.
    I have another table with all of the Week Numbers for a given year in the first column and a second column in which I would like a formula to count the numbers of dates in Table A that correspond to the Week Number in the first column (i.e. the number of dates that falls within that week).
    The following statement works for testing single cells:
    =COUNTIF(WEEKNUM(Table A :: $Session 1 $January,2),A1)
    But it would seem that I can only use this with single cells and not the table as a whole.
    Could someone help with a solution to this?
    Thanks,
    Nick

    Thanks Jerry.  If I have understood you correctly I would need to calculate the week numbers of the dates in Table A in Table A itself, like this:
    Then I would use the COUNTIF function to test the array of week numbers in Table A.  If this is correct, I am not sure how to construct an array that includes just the cells with week numbers. I presume I could do this either manually or based on the value in the first column of Table A (i.e. just testing the five columns to the right of each "Week No" row), but I'm not sure.
    Nick

  • To find out the number users that logged in to SAP in previous months

    Hi !
    Is theer any report or transaction in SAP that will or can tell us as to how many users had logged into SAP syatem say in the month of May or June . They want to know the total number of users that had logged in to SAP in previous months to to track the user information and how many users are not using the SAP or how many ppl using it to keep a track of teh user certificates that may be re-sed or just for information purpose also. Right now I have found a trabsction AL08 but that just gives information of present login , I would like to get it for previous months if possible.
    Thanks

    But this does not give the details of the all the users that had logged in and as to how many users were logged in that month and at what times .Is theer any other transaction that gives the user information also.?
    Thanks

  • Return the end of week date using month and week number

    Hi all,
    I am trying to find the date for end of the week using given month (201401, 201402...i.e, 2014 is year and 01,02 are months) and week number (01,02,03...) for the year. For example if my month is 201402 and week_number is 06 then it return the week_date
    as 2014-02-08. Can you please help me in writing a sql statement for this scenario.
    Thanks in advance,
    Nikhil

    Current month is irrelevant
    with dt as (
       select dateadd(day, (6-1)*7, '2014-01-01') as xwk
    select dateadd(day, 7-datepart(weekday, dt.xwk), xwk)
    from dt;
    Change the "6" in the with statement to the week of interest and 2014 to the year of interest...

Maybe you are looking for

  • New line character in cipher text?

    Friends, I am encrypting a text in Triple DES/CBC mode/Nopadding mode. the length of text is 6500 bytes. in the cipher text that i get, it has new-line character(\n) & carriage return characters. As a result of this i m unable to read the cipher text

  • Hyperion Interactive reporting - Pivot Section Facts Sequence / Order

    Requirement : Dynamically populating Month Name & Year as Column Name. Challenges : Using a computed colum and variable, we are able to assign the variable to the computed column and get the values as desired. We have 7 non computed columns and 12 co

  • Airport Wirless Router Linksys

    have a wireless Linksys router that I put a 128 bit encryption. It was driving me mad that when booted up in OS 9 I could not use my password. I tried using the entire 24 character code as a password, and it works. That is how you use 128 bit encrypt

  • Create History Table from Main

    I'm seeking help from the experts because I'm far from an expert and I have been unsuccessful at figuring this out on my own. So far I've created a history table which is to keep all our data history from our main table. It is almost the same table,

  • How to add a horizontal line in RoboHelp HTML 7

    HI - I am working with RoboHelp 7 HTML. I want to add a horizontal line to my topic. I am using RoboHelp as my editor. Work mostly in WYSWYG / Design mode and don't do much hand coding as a rule, but sometimes I tweak the code. Since I couldn't find