Calculate Weeks in a period

Hi All,
How do I calculate the number of weeks in a given period.
say for example
startDate = 24th Nov 2002
enddate = 31st dec 2002.
How can I find the weeks within this period.
I tried calculating the time difference but that didn't help.
Any Ideas?

codingMonkey wrote:
gcameo wrote:
Weeks as in calendar weeks (Sunday - Saturday = 1 week) or just seven consecutive days (Wednesday - Tuesday = 1 week)?7 Consecutive daysThe easiest way, without using a third party library, in my opinion is the following. Get the difference between the two dates in milliseconds, divide that by 1000 to get seconds, divide by that 60 to get minutes, and so forth until you get the difference in weeks. I'll leave it up to you to write the code. Good luck!
As always, there might be a class/method somewhere in the standard API which provides an easier way of doing this. If anyone knows of such a class or method, please enlighten me and the OP.I have used the Joda-time library extensively before for this kind of work but in my current company, "ReInvent the Wheel Limited", I can't use it...hence my struggles.
Anyway, thanks

Similar Messages

  • Find the no of weeks in a period

    Hi Experts,
    Could any one let me know the function module to find the no of weeks in a period ?
    Regards,
    Prem

    You can use DATE_GET_WEEK  with from and to dates and subtract (+1)
    Regards

  • Calculate week no based on financial year

    Hi
    Financial year starts with 01-Apr . I need to calculate week no based on 01-APR(financial year) not 01-Jan
    for each date. Is there a way to calculate based on this

    It works for all year long :-)
    SQL> ed
    Wrote file afiedt.buf
      1  with testdata as (
      2     select date '2011-04-01' + 7 * (level-1) dt from dual
      3     connect by level <= 60
      4  )
      5  --
      6  -- End of test data
      7  --
      8  select
      9  to_char(dt,'YYYY-MM-DD') the_date,
    10  to_char(add_months(dt,-3),'WW') fiscal_week,
    11  to_char(add_months(dt,-3),'IW') iso_fiscal_week
    12  from testdata
    13* order by dt
    SQL> /
    THE_DATE   FI IS
    2011-04-01 01 52
    2011-04-08 02 01
    2011-04-15 03 02
    2011-04-22 04 03
    2011-04-29 05 04
    2011-05-06 06 05
    2011-05-13 07 06
    2011-05-20 08 07
    2011-05-27 09 08
    2011-06-03 09 09
    2011-06-10 10 10
    2011-06-17 11 11
    2011-06-24 12 12
    2011-07-01 13 13
    2011-07-08 14 14
    2011-07-15 15 15
    2011-07-22 16 16
    2011-07-29 17 17
    2011-08-05 18 18
    2011-08-12 19 19
    2011-08-19 20 20
    2011-08-26 21 21
    2011-09-02 22 22
    2011-09-09 23 23
    2011-09-16 24 24
    2011-09-23 25 25
    2011-09-30 26 26
    2011-10-07 27 27
    2011-10-14 28 28
    2011-10-21 29 29
    2011-10-28 30 30
    2011-11-04 31 31
    2011-11-11 32 32
    2011-11-18 33 33
    2011-11-25 34 34
    2011-12-02 35 35
    2011-12-09 36 36
    2011-12-16 37 37
    2011-12-23 38 38
    2011-12-30 39 39
    2012-01-06 40 40
    2012-01-13 41 41
    2012-01-20 42 42
    2012-01-27 43 43
    2012-02-03 44 44
    2012-02-10 45 45
    2012-02-17 46 46
    2012-02-24 47 47
    2012-03-02 48 48
    2012-03-09 49 49
    2012-03-16 50 50
    2012-03-23 51 51
    2012-03-30 52 52
    2012-04-06 01 01
    2012-04-13 02 02
    2012-04-20 03 03
    2012-04-27 04 04
    2012-05-04 05 05
    2012-05-11 06 06
    2012-05-18 07 07
    60 rows selected.ISO Week (IW) works with a different way of defining week 01. Using IW April 1st will become week 52. You will have to decide if that is correct according to your finance department :-)

  • How to calculate week number from system date

    Hi experts,
    how to calculate week number from system date  ?
    thanks.
    SK

    hi,
    The above FM can be used for BADI or customer exit, if it is design level then you can use formula as well, under formula date functions you can use DATE_TO_WEEK.
    regards,
    Arvind.

  • In repeat run, can i calculate Depreciation for perticular period.

    Hi
    when I calculate the depreciation in Repeat Run, It shows the message that for 12 periods only the Dep is calculated.
    But I want to calculate the Dep for Particular period. Is it possible?????
    If possible pl give me the suggession
    Venkata Raju

    Hi,
    You can't do.
    See below note:
    It is possible to repeat the posting run within the period last posted. However, in contrast to the first run for a period, the repeat run can be restricted to specific assets. In the repeat run, the system posts changes to depreciation, as compared to the depreciation amounts from the previous run.
    Normally the repeat run is carried out at the end of the fiscal year, if completing postings are necessary because of corrections to manual depreciation or depreciation terms.
    Regards,
    Murali

  • Formula to calculate two fiscal year/period difference for non null quantit

    We'd like to have a query result like the following:
    Person -- Jan_2007 -- Feb_2007 -- Mar_2007  --  No. of Months
    Tom --- 21 --- 54 --- 10 --- 2
    John --- 0 ---  3 --- 15 --- 1  
    In the above query, the row is sales persons, the 1st three columns list the sales quantity by each sales person restricted by fiscal year/period and we would like to create 4th column "No. of Months" to calculate (will use formula) the month span (difference) for each sales person from his last sale activity (the last month he performed sales) and the 1st sale activity (the first month he performed sales) as listed in the above query result, e.g.,  Tom performed his first sales (sales quantity: 21) in the month of January of year 2007, and he performed his last sales (sales quantity of 10) in the month of March, 2007, then the "No. of Months" column value for Tom is 2.  The calculation formula will be performed based on the last quantity value (> 0) to trace it's corresponding column fiscal year/period value (max of the fiscal year/period value with quantity value >0) and on the 1st quantity value (>0) to trace it's corresonding column fiscal year/period value (min of the fiscal year/period value with quantity value >0) and then do the subtraction between the max of the fiscal year/period value and the min one. 
    Would be appreciated if BEx experts here give the detailed steps on how to build up this formula to calculate the number of month difference and we will give you reward points!
    Edited by: Kevin Smith on Mar 18, 2008 1:47 PM

    hi Danny,
    I only gave an example of 3 columns, but actually, yes, the report can have more than 12 months, e.g. from Jan_1999, Feb_1999, ..., Mar_2011, Apr_2011.
    In our simple example of 3 columns for the three consecutive months, if John had (3)(0)(15), then the No. of Months is 2, or the last month value he performed sales and 1st month he performed sales.
    You said macro in Excel sheet?  Not sure if macro will work on web since we will eventually run the reports on web browser, therefore we still prefer using Formula.
    Any idea/solution?
    Thanks!

  • HFR: How to calculate variation over last period for dynamic columns

    Hello Everyone,
                             How to calculate the period wise variation in a report where the period columns are dynamically generated from a range function? For example, the range function in the period column is &Current:Dec. What formula can I write in a calculated row so that the value is (Current  Period - Previous period)*100/Previous period ?
    Thanks,
    Sayantan

    You can add two more data rows.
    1. Use &Current
    2. Use relativemember function, select &Current, offset -1 (If you've a subvar for previous month that's the best)
    3. Add a formula row ([B]-[C]*100/[C])
    Regards
    Celvin
    http://www.orahyplabs.com

  • FOX: how to calculate weeks totals?

    All, I need to calculate the suggested order order quantity (KF = ZPOSUGQTY) for a vendor/material combination. For this I need to calculate,
    the total sales quantity (KF 0QUANTITY) of the last 4 weeks (so 'current week - 1' till 'current week - 4')
    the total sales quantity of week 5 till 9 (so 'current week - 5' till 'current week - 9')
    In my fields to be changed I have 0MATERIAL and 0VENDOR. 0CALWEEK is in the aggregation level. My plan is to get current week via the VARV/VARC statement from a Bex variable.
    I am not sure how to get the 4 week total and the 5-9 week total though. I start off with FOREACH MATERIAL VENDOR. But what would the code look after that?
    Any help appreciated! Cheers.

    Thanks Cornelia. I used the code below. It is not working though. I tried to debug it, there are a couple of problems
    - the IF statement on CALWEEK is not working, the program does not seem to be able to calculate lower/higher compared to eg
    CURWEEK1
    - I think the program is calculating the formula per week. What I need is calulate the total sales figures for the last 4 weeks, then total sales of week 5-9. When this is done execute the formula to calculate ZPOSUGQTY. So the formula should only be calculated once for a material. For this I should not have 0CALWEEK in my fields to be changed? How would a DO statement fit below? FYI I have omaterial and 0calweek in my fields to be changed.
    DATA MATERIAL TYPE 0MATERIAL.
    DATA CALWEEK TYPE 0CALWEEK.
    DATA TOT_SALES_1TO4 TYPE F.
    DATA TOT_SALES_5TO9 TYPE F.
    DATA CURWEEK TYPE 0CALWEEK.
    DATA CURWEEK1 TYPE 0CALWEEK.
    DATA CURWEEK4 TYPE 0CALWEEK.
    DATA CURWEEK5 TYPE 0CALWEEK.
    DATA CURWEEK9 TYPE 0CALWEEK.
    BRING IN CURRENT WEEK PLUS DERIVED WEEKS
    CURWEEK = VARV ('0CWEEK').
    CURWEEK1 = TMVL(CURWEEK, -1).
    CURWEEK4 = TMVL(CURWEEK, -4).
    CURWEEK5 = TMVL(CURWEEK, -5).
    CURWEEK9 = TMVL(CURWEEK, -9).
    *INITIALIZE THE LOCAL KEY FIGURES
    TOT_SALES_1TO4 = 0.
    TOT_SALES_5TO9 = 0.
    FOREACH MATERIAL, CALWEEK.
      IF CALWEEK <= CURWEEK1 AND CALWEEK >= CURWEEK4.
          TOT_SALES_1TO4 = TOT_SALES_1TO4 + {0ACT_DL_QTY, CALWEEK, MATERIAL}.
      ELSEIF CALWEEK <= CURWEEK5 AND CALWEEK >= CURWEEK9.
             TOT_SALES_5TO9 = TOT_SALES_5TO9 + {0ACT_DL_QTY, CALWEEK, MATERIAL}.
      ENDIF.
    ENDFOR.
    {ZPOSUGQTY, CALWEEK, MATERIAL} = (2 * TOT_SALES_1TO4 + TOT_SALES_5TO9 )/ 13.

  • Record, calculate and save data periodically

    Hi,
    I am working on a labview project. I have a continuous input data which is updated every 100ms. I need to calculate the 15 minutes average value, one hour average value of this input data and save this average values into excel file continuously. I have problem about how to calculate the 15 minutes average input data value. I have look through some example for parallel while loop, but my main problem is how to calculate the 15 minutes average values periodically and save it to the file. Thanks for your help.
    Fred

    You do not need parallel loops to calculate a running average. Just keep two arrays of old data in a shift register inside the same loop. The first array is 9000 points (15 min) and the second is 36000 points (1 hr).
    Append new data to the top of the array and delete any excess points from the bottom. Calculate the average on the entire array every time you add a point and write these values to other Excel columns.
    Michael Munroe
    www.abcdef.biz
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • Calculate week number (DIN EN 28601)

    HI,
    how can I calculate the proper week number for Germany? So the first
    week in year is the week with at least four days (Thursday at least
    01.01). So I have some problems with leap years and so on. One of the
    problems is to know that the last days of a year can be in the first
    week of next year (such as 31.12.2002).
    Who can help me?
    Thanks and best regards
    Marco

    JB wrote:
    Yes, this is a great VI ! Thanks Rolf !
      However, we have modified it sligthly to handle some strange cases that may occur.
      One
    of those strange cases was the first day of this year.
    The weeknumber was 52 and the year 2006. Although both are
    correct, you will get an erroneous date if you combine them. In fact,
    if you label a product with this date, the customer will think that it
    was produced the last week of 2006.
      In this case, you must either change the weeknumber to 1 or the year to 2005.
      There are some other modifications like the input type of the date that we changed to a time stamp control.
    What
    you did are practical modifications but they are not to the definition
    of the ISO norm. If you modify week to 1 the supposed date is one week
    later than what ISO really means and only if you change year to 2005
    are you sort of correct.
    I didn't use the time stamp string because this function was written in
    a LabVIEW version that hadn't a timestamp type and can be loaded in
    such LabVIEW versions AFAIR.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • 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

  • I want logic to calculate mateiral wise and period wise

    can anyone please tell how to consider material and period for this pgm
    i have coded to calcualte sum of material wise.
    but i want to consider materila wise and month wise
    eg:material   quantity month
        1000        200       4/2001
         1000       300       5/2001 based on the below conditions.
    Select  mATNR SPMON ZZDPFC ZZMARKET
    From S507
      into corresponding fields of  table  t_DATA WHERE
      VRSIO = '000' AND BEDAE = 'KSV' AND ZZDMTYP = '001'
      AND  ZZDPFC GT '0' AND ZZMARKET IN ('001','002') AND SPMON >= 200705.
       SORT T_DATA BY MATNR ZZMARKET SPMON.
    write:/04 'Material',25 'Demand Plant'. "45 'Market',70 'Period'.
    LOOP AT T_DATA.
    WRITE:/02 t_data-MATNR ,25 t_data-ZZDPFC,45 t_data-ZZMARKET,
    70 t_data-SPMON.
    at end of matnr.
    sum.
    write : /02 t_Data-matnr,25 t_data-zzdpfc COLOR 5 .
    endat.
    endloop.

    Hi,
    <fs> type   t_data
    sort t_data by matnr  month.
    V_index = 0.
    loop at  t_data  assigning <fs>.
    V_index = sy-tabix + 1.
    read  t_data assigning <fs2> with  index V_index .
    if sy-subrc = 0.
    --if <fs>-matnr =  <fs2>-matnr and <fs>-month = <fs2>-month.
    <fs>-quantity =  <fs>-quantity =  <fs2>-quantity.
    delete  t_data index V_index.
    --endif.
    endif.
    endloop.
    <b>then loop at  t_data to display .</b>
    Regards,
    Sooness.

  • How do I calculate the difference between periods in Crosstab

    Using Discoverer 4.1 with 11i General Ledger.
    I want to do a crosstab report that compares the differences in amounts from one period to another.
    The table is:
    ACCOUNT - PERIOD - AMOUNT
    Down the left it will show the account number, across the top it will show this month and last month, and the data point is period net. I want a third column that will show the difference between them.
    Example:
    _______JAN-04___FEB-04__Change
    4000____10.00____15.00____5.00
    5000____20.00____30.00___10.00
    6000____30.00____45.00___15.00
    7000____40.00____60.00___20.00
    Is this possible in Discoverer?

    The only way I know of to do what you are asking is to create a calculated field (previous_period) using the lag function
    lag(period_net,1) over (partition by account order by period) then create another calculated field (change) (period_net - previous_period). You might want to review the syntax of the lag function, I'm not sure it's exactly right, but it's in the ball park.
    Hope this helps. If anyone else is got a better way, I would sure like to know, because this is causing us headaches also.
    Thanks,
    Carl Petersen
    Good Humor - Breyers Ice Cream

  • An update after a few weeks burn in period of my iPod HiFi

    Hello all,
    Today, the long Easter Holiday started, so I told myself why not have a good relax holiday with listening to my iPod, I connected my iPod with my Goldmund reference stereo system and a pair of B&W 800 speakers. Humm ... not very impressive, I understood all the music on my iPod were compressed files, they were far behind from the music played from a CD, and I was wrong that by connecting with a good Stereo system would improve the iPod's sound quality a lot. So a bit disappointed, after listening a couple of songs, I switched the system off. Instead, I plug my iPod with my iPod HiFi, let it played as a background music and reading the book "iCon Steve Jobs".
    What a prefect match between iPod with the iPod HiFi, playing the compressed music files with no complain.

    Good morning, my friend.
    Yeah, the price is higher than Bose sounddock or Jbl's products.
    For Bose and JBL - I classified them a higher grade computer speakers or at a level same as Mini Stereo.
    But iPod HiFi is totally different level, (I do not ever say that it is around the audiophile level). Its sound great and it can fill a room as big as 200 square foot room easily.
    Please read this post - hope can give you some light
    http://discussions.apple.com/thread.jspa?threadID=410169&tstart=15
    In general, iPod HiFi is perfectly match with iPod, it is one of my best investment, and one of best speaker for background music.
    You would not believe that I spent US$2000 for a pair of B&O speakers 3 years ago, for the purpose of connecting with my iPod, I am thinking now to sell this B&O in secondary market, as I would much prefer with iPod HiFi - But again, I am just talking of playing the iPod's compressed music files.

  • Regarding Customer exit to calculate fiscal week

    Hello All,
                 I have a requirement to calculate the fiscal week from fiscal period. Here i used the FM 'UMC_FISCPER_TO_CALWEEK' to calculate the fiscal week. But the problem here is i created variable on fiscal year /week so when i pass the fiscal period i should get fiscal week, here i am getting calweek which make no sence. Is there any function module to calculate the Fiscal week if we pass fiscal period.
    Thanx in Advance
    Anil

    We cant calculate fiscal week from just fiscal period. we need date or this.
    You can try this function  ZFI_GET_FISCAL_WEEK_QUARTER or some other similar function. However, the input should be a date.
    Looks like there is no funciton to calculate fiscal week. we may need to write our own code for this based on other FMs.
    Re: Get Week number in a particular Fiscal year
    ~ Arun KK
    Edited by: arun kk on May 8, 2008 10:22 AM

Maybe you are looking for

  • Does it exist a manual for learning to use Oracle Forms?

    What I'm looking for is a manual or tutorial for using Oracle Forms. Looking at Oracle Documentation link http://www.oracle.com/technetwork/developer-tools/forms/documentation/10g-forms-091309.html I haven't found an user or developer guide. On the w

  • PDF files in iBooks will not finish downloading

    I have attempted to download several PDF files in iBooks but they won't finish downloading and I cannot delete them. What do I do?

  • ITunes Closes When PC Is Idle

    Whenever I run iTunes (v. 6.0.3.5/Windows XP SP2 Pro) in the mini-player, if I pause it and go away for a while, I come back to find it's closed itself down (no error messages or anything, just turned itself off). Any ideas?

  • UCCX and WFO upgrade

    Hi all, I need to perform an upgrade for a client of UCCX 7 with Workforce Optimization to the latest and greatest, but I'm having trouble determining exactly what I need to order from the Product Upgrade Tool. Especially with the QM component, as th

  • MSI Neo4-F & Athlon64 3700+ E6 1T/2T Memory Timing missing in BIOS

    Hi. This is my first post. I need help with my new MSI Neo4-F motherboard. The problem is that 1T/2T Memory Timing is not present in the latest BIOS v.1D. MSI website says that my CPU (San Diego 3700+ E6) is supported by the motherboard but there is