No of weeks in a year

hi experts,
i want to calculate the no of weeks in any year entered by user .But the week calculation is the the form of technical weeks(TW).
1) Technical week starts from monday  or first day of the month
2) Technical week ends on sunday or last day of the month
example For year 2007
From      |                   To           |              Technical_week      | ActualWeek
JAN 
01/01/2007       |  07/01/2007       |               1TW         |            1
08/01/2007       |  14/01/2007       |                2TW        |            2
15/01/2007       | 21/01/2007        |              3TW          |            3
22/01/2007       |   28/01/2007      |               4TW         |            4
29/01/2007       |     31/01/2007    |               5TW         |            5
FEB
01/02/2007      |     04/02/2007      |                6TW        |            5
05/02/2007      |    11/02/2007       |              7TW          |            6
12/02/2007      |    18/02/2007       |              8TW          |            7
19/02/2007      |     25/02/2007      |              9TW          |            8
26/02/2007      |     28/02/2007      |             10TW         |            9
LIKE wise TW will be more than actual weeks in year 2007...
So in 2007 there are 52 actual weeks and 63 TW...
I want to calculate TWs for ANY year given by user on selection screen....
is there any function module for this... or can we create it... Need some logic
thanks in advance
Bijal

Hi Bijal,
Logic is as follows.
CONSTANTS: gc_days_in_week  TYPE i VALUE 7.
DATA: gf_days               TYPE i,
      gf_techwks            TYPE i,
      gf_month(2)           TYPE n,
      gf_begda              TYPE d,
      gf_endda              TYPE d,
      gf_monday             TYPE d,
      gf_sunday             TYPE d.
PARAMETERS: p_year(4)       TYPE n.
gf_month = 1.
gf_techwks = 0.
DO 12 TIMES.
  CONCATENATE p_year gf_month '01'
              INTO gf_begda.
  CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
    EXPORTING
      iv_date             = gf_begda
    IMPORTING
      ev_month_begin_date = gf_begda
      ev_month_end_date   = gf_endda.
* Check Begin Date start of the week
  CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
    EXPORTING
      date   = gf_begda
    IMPORTING
      monday = gf_monday
      sunday = gf_sunday.
  IF gf_begda <> gf_monday.
    gf_begda = gf_sunday + 1.
    ADD 1 TO gf_techwks.
  ENDIF.
* Check End Date end of the week
  CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
    EXPORTING
      date   = gf_endda
    IMPORTING
      monday = gf_monday
      sunday = gf_sunday.
  IF gf_endda <> gf_sunday.
    gf_endda = gf_monday - 1.
    ADD 1 TO gf_techwks.
  ENDIF.
* Rest of the weeks
  gf_days = gf_endda - gf_begda.
  gf_techwks = gf_techwks + ( gf_days / gc_days_in_week ).
  ADD 1 TO gf_month.
ENDDO.
WRITE:/ 'Technical Weeks : '(001), gf_techwks.
I know you can still optimize it in terms of variables' usage : )
Regards,
Manish Joshi
I hope you know what to do now.
Message was edited by:
        Manish Joshi

Similar Messages

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

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

  • 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

  • Want to create analysis for this year week vs last year week

    All,
    My requirement is to create an analysis for the passed week number of this year vs same last year week no.
    So basically user will pass the week no. and report should display the passed week no. this year sales number plus same week no. last year sales number.
    How can I achieve this?
    Thanks

    If you ask like this ..I would say like using presentation variable for week
    use measure with exp like
    CASE WHEN WEEK=@{WK} AND Time.year=VALUEOF("PREVIOUS_YEAR") THEN #sales END.
    In this case week is from your subject area and PREVIOUS_YEAR is rep variable you might have it.
    there are other options to get output, need details about your rpd and value of week.

  • Fm - how many weeks 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 Priya,
    There is a function module 'TIME_GET_LAST_WEEK'.
    In this FM, export the Year & you will get(Import) a value in a parameter
    EF_WEEK. This will be the Concatenated String of Year&Number_of_weeks in that year
    For Example If you run this FM for the Year 2004, the Parameter EF_WEEK will
    be '200453'. That means last two digits gives the number of weeks in that year.
    From this value you can easily get number of weeks (i.e,EF_WEEK+4(2)).
    If this value is 53, then it is a leap year, else not a leap year
    Regards,
    Sreenivas Reddy Maddi

  • Determining current week of a year

    Hi,
    is anybody have idea, how to determine the current week of a year.
    Please give some ideas.
    Thanks

    something like
    Calendar cal = new GregorianCalendar();
    int weeks = cal.get(Calendar.WEEK_OF_YEAR));
    ?

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

  • Weeks in a Year

    Hi guys. Hope you can give me a heads up here. I have the year as the only input, how can I produce all the weeks for that year....lets say for 2007
    week 1 = Jan 6 - 12
    week 2 = jan 13 - 19
    week 3 = jan 20 - 26
    week 4 = jan 27 - feb 2
    etc...

    SQL> var year varchar2;
    SQL> exec :year:='2007';
    PL/SQL procedure successfully completed
    year
    2007
    SQL> set pagesize 1000;
    SQL>
    SQL> with t as (select trunc(to_date(:year, 'yyyy'), 'y') first_date from dual),
      2  t1 as (select t.*,5-mod(to_char(first_date,'j'),7) diff from t),--depending on the first day of week you should place a number: 5-saturday, 6-sunday, 0-monday
      3  t2 as (select first_date, first_date+decode(sign(diff),-1,7+diff,diff) fws  from t1),
      4  t3 as (select level lev, fws + 7 * (level - 1) fd,fws + 6 + 7 * (level - 1) ld
      5    from t2
      6  connect by to_char(fws + 7 * (level - 1), 'yyyy') = :year)
      7  --
      8  select 'week ' || lev || ' = ' || to_char(fd, 'mon dd') || ' - ' ||
      9         to_char(ld,
    10                 decode(to_char(fd, 'mm'), to_char(ld, 'mm'), 'dd', 'mon dd')) week
    11    from t3
    12  /
    WEEK
    week 1 = jan 06 - 12
    week 2 = jan 13 - 19
    week 3 = jan 20 - 26
    week 4 = jan 27 - feb 02
    week 5 = feb 03 - 09
    week 6 = feb 10 - 16
    week 7 = feb 17 - 23
    week 8 = feb 24 - mar 02
    week 9 = mar 03 - 09
    week 10 = mar 10 - 16
    week 11 = mar 17 - 23
    week 12 = mar 24 - 30
    week 13 = mar 31 - apr 06
    week 14 = apr 07 - 13
    week 15 = apr 14 - 20
    week 16 = apr 21 - 27
    week 17 = apr 28 - may 04
    week 18 = may 05 - 11
    week 19 = may 12 - 18
    week 20 = may 19 - 25
    week 21 = may 26 - jun 01
    week 22 = jun 02 - 08
    week 23 = jun 09 - 15
    week 24 = jun 16 - 22
    week 25 = jun 23 - 29
    week 26 = jun 30 - jul 06
    week 27 = jul 07 - 13
    week 28 = jul 14 - 20
    week 29 = jul 21 - 27
    week 30 = jul 28 - aug 03
    week 31 = aug 04 - 10
    week 32 = aug 11 - 17
    week 33 = aug 18 - 24
    week 34 = aug 25 - 31
    week 35 = sep 01 - 07
    week 36 = sep 08 - 14
    week 37 = sep 15 - 21
    week 38 = sep 22 - 28
    week 39 = sep 29 - oct 05
    week 40 = oct 06 - 12
    week 41 = oct 13 - 19
    week 42 = oct 20 - 26
    week 43 = oct 27 - nov 02
    week 44 = nov 03 - 09
    week 45 = nov 10 - 16
    week 46 = nov 17 - 23
    week 47 = nov 24 - 30
    week 48 = dec 01 - 07
    week 49 = dec 08 - 14
    week 50 = dec 15 - 21
    week 51 = dec 22 - 28
    week 52 = dec 29 - jan 04
    52 rows selected
    year
    2007

  • 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

  • Sql to get the Monday of every IW week in a year!

    Hi There!
    This is an SOS :) I had to get a query to give me all the Mondays of a IW week in a year. I think as per the IW weeks there are around 52.1 weeks in a year. So basically, I want the starting Monday of every week. I would then store those values in a variable and use them in APEX as column headers. Online I saw some samples not related with this, but where looping was done using the all_objects. Not sure if that is the right approach.
    The problem is since this is not stored in any table, how can I loop like 52/53 times such that the output shows all the Mondays (date format) for a given year. Basically, the output would be 52/53 rows with a date(monday of the week).
    Please help!
    thanks,
    Sun
    Edited by: ryansun on Jun 28, 2012 11:09 PM

    Would this be something you are looking for?
    SQL> variable yr number
    SQL> exec :yr := 2015
    SQL> with dates as (
      2  select to_date('0101'||:yr,'ddmmyyyy')-4+level da
      3    from dual
      4  connect by level < 373
      5  )
      6  select :yr iyyy, to_char(da,'IW') iw, da monday
      7    from dates
      8   where to_char(da,'dyiyyy', 'nls_date_language=american')='mon'||:yr
      9  ;
          IYYY IW       MONDAY
          2015 01       29-12-2014
          2015 02       05-01-2015
          2015 03       12-01-2015
          2015 04       19-01-2015
          2015 05       26-01-2015
          2015 06       02-02-2015
          2015 07       09-02-2015
          2015 08       16-02-2015
          2015 09       23-02-2015
          2015 10       02-03-2015
          2015 11       09-03-2015
          2015 12       16-03-2015
          2015 13       23-03-2015
          2015 14       30-03-2015
          2015 15       06-04-2015
          2015 16       13-04-2015
          2015 17       20-04-2015
          2015 18       27-04-2015
          2015 19       04-05-2015
          2015 20       11-05-2015
          2015 21       18-05-2015
          2015 22       25-05-2015
          2015 23       01-06-2015
          2015 24       08-06-2015
          2015 25       15-06-2015
          2015 26       22-06-2015
          2015 27       29-06-2015
          2015 28       06-07-2015
          2015 29       13-07-2015
          2015 30       20-07-2015
          2015 31       27-07-2015
          2015 32       03-08-2015
          2015 33       10-08-2015
          2015 34       17-08-2015
          2015 35       24-08-2015
          2015 36       31-08-2015
          2015 37       07-09-2015
          2015 38       14-09-2015
          2015 39       21-09-2015
          2015 40       28-09-2015
          2015 41       05-10-2015
          2015 42       12-10-2015
          2015 43       19-10-2015
          2015 44       26-10-2015
          2015 45       02-11-2015
          2015 46       09-11-2015
          2015 47       16-11-2015
          2015 48       23-11-2015
          2015 49       30-11-2015
          2015 50       07-12-2015
          2015 51       14-12-2015
          2015 52       21-12-2015
          2015 53       28-12-2015
    53 rows selected.

Maybe you are looking for