Calculation Based on Previous Day's Figure

Hi all,
This is a solution I implemented several years ago, which is now causing problems and must be rectified.  The intention was to compare a single field across two days and calculate the difference.  The only way I could figure out how to do that
back then was to go back and loop through the whole table, calculating the difference each day until the present day.  This obviously isn't very efficient and now something has gone wrong.
Here's the code:
// Calculates Nett Oil Volume Increase
double previousNettOilVolA = 82433; // value on 2/1/13 which is the live value on the day before this system begins
double previousNettOilVolB = 51347; // value on 2/1/13 which is the live value on the day before this system begins
foreach (DailyTankData tankdata in DataWorkspace.ApplicationData.DailyTankDatas)
if (tankdata.NettOilVolume15TankA != null)//otherwise will crash if null value
tankdata.NettOilVolumeIncreaseTankA = (double)tankdata.NettOilVolume15TankA - previousNettOilVolA;
previousNettOilVolA = (double)tankdata.NettOilVolume15TankA;
tankdata.NettOilVolumeIncreaseTankB = (double)tankdata.NettOilVolume15TankB - previousNettOilVolB;
previousNettOilVolB = (double)tankdata.NettOilVolume15TankB;
This is run on the _Compute event of another property in the table.  It seemed to work for a long time, but now is occasionally giving wildly inaccurate numbers.
What's a better way to solve this problem?  Failing that, can anyone explain exactly how the above works and why it might be going wrong?
Thanks,
Liam

Start by looking at your data. Any unusual spikes or negative values?
A better way to handle it is to let the database do the calculations via a stored procedure.

Similar Messages

  • How to fetch the data records in summary format based on previous day

    drop table T1;
    create table T1(Class, Fees_Collected, Submit_Date) as select
    'MBA', 100000, '7/30/2012' from dual union all select
    'Btech', 20000, '7/10/2012' from DUAL union all select
    'MBA', 45000, '8/1/2012' from dual union all select
    'Btech', 55550, '7/31/2012' from DUAL union all select
    'BBA', 250660, '7/30/2012' from dual union all select
    'MBBS', 44556000, '7/31/2012' from DUAL union all select
    'BDS', 420050, '8/1/2012' from DUAL union all select
    'BBA', 30450, '7/30/2012' from DUAL union all select
    'MBBS', 120450, '7/31/2012' from DUAL union all select
    'BDS', 45950, '7/30/2012' from DUAL union all select
    'MBA', 252450, '8/1/2012' from DUAL;My requirment is to fetch the records based on summary format to display the data with following columns -
    Class |Prev Day Traded Value |Prev Day % of Total |Prev Day % MBA
    Note - Previous Day definiton (Buisness Day) = calendar days - (weekends + US Holidays)
    Kindly help me, as i want to keep it customized so that without specifying the hard coded dates ( Previous Day) it runs through and provide me the resultset....
    All of your help and time is highly appericated.

    You mean business days I guess ?
    I use a function (I had to write it myself) <tt><b> next_business_day(p_start_date in date,p_days_count in number) return date </b></tt>
    where I loop forward/backward from p_start_date according to the sign of p_days_count the required number of steps skipping weekends and holidays as the absolute value of p_days_count is mostly under 30 for the rest (at least around here) Oracle's <tt><b> add_months </b></tt> gets it done.
    Regards
    Etbin
    Edited by: Etbin on 6.8.2012 17:55
    Year till date: <tt><b> your_date between trunc(sysdate,'year') and sysdate </b></tt> is it ? http://en.wikipedia.org/wiki/Year-to-date ?
    Edited by: Etbin on 6.8.2012 18:27
    NOT TESTED!
    function next_business_date(p_start_date in date,p_count_days in number) return date is
      steps  number := abs(p_count_days);
      retval date := p_start_date;
    begin
      if p_start_date is null or p_count_days is null then
        return to_date(null);
      end if;
      while steps > 0
      loop
    /* skipping weekends and (yet to be implemented) holidays */
        while to_char(retval,'dy') in ('sat','sun') /* or is_holiday(retval) */
        loop
          retval = retval + sign(p_count_days);
        end loop;
    /* retval contains a business day now */
        retval = retval + sign(p_count_days);
        step := step - 1;
      end_loop
      return retval;
    end;

  • Moving average price calculation based on year to date figures

    Hello,
    I've been working for months on the stock valuation at month end closing for the Finance department. We discover a situation where the moving average price is not calculated as we expected.
    The situation is as follows:
    2 purchase orders for the same material at different periods and with different purchase order prices
    the invoice of the first pruchase order has been recorded after the good receipts of the 2 purchase orders with purchase price variance, good issues have been recorded between the good receipts and the first invoice receipt, therefore the stock quantity is lower than the quantity invoiced
    the invoice of the second purchase order has been recorded as well with price purchase variance after the first invoice and after good issues, therefore the stock quantity is lower than the quantity invoiced.
    Here is an example with figures:
    SAP Calulation
    Good entry
    Good Issue
    Before Posting
    After Posting
    Good receipt
    Invoice receipt
    Date
    Movement
    Quantité
    Price
    Value
    Quantité
    Price
    Value
    Quantité
    Value
    PMP
    Quantité
    PMP
    Value
    Quantité
    PMP
    Value
    01.01.2014
    Intial Stock
    2000
    11
    22000
    16.01.2014
    Purchase Order 1
    10000
    10
    100000
    2000
    11
    22000
    12000
    10,17
    122040
    20.01.2014
    Good issue
    2000
    20340
    10,17
    12000
    10,17
    122040
    10000
    10,17
    101700
    18.02.2014
    Purchase Order 2
    20000
    9
    180000
    10000
    10,17
    101700
    30000
    9,39
    281700
    22.02.2014
    Good issue
    22000
    9,39
    206580
    30000
    9,39
    281700
    8000
    9,39
    75120
    30.03.2014
    Purchase Order 1
    10000
    9,5
    95000
    8000
    9,39
    75120
    8000
    8,89
    71120
    21.04.2014
    Good issue
    2000
    8,89
    17780
    8000
    8,89
    71120
    6000
    8,89
    53340
    31.05.2014
    Purchase Order 2
    20000
    7
    140000
    6000
    8,89
    53340
    6000
    6,89
    41340
    - When the first invoice is recorded, SAP calculate the MAP this way: ( 8000*9,39 + (95000-100000) * (8000/10000) ) / 8000 = 8,89
    - When the second inoice is recorded, SAP calculate the MAP this way: ( 6000*8,89 + (140000-180000) * (6000/20000) ) / 6000 = 6,89
    Moving average price calculation requirement
    Good entry
    Good Issue
    Before Posting
    After Posting
    Good receipt
    Invoice receipt
    Date
    Movement
    Quantité
    Price
    Value
    Quantité
    Price
    Value
    Quantité
    Value
    PMP
    Quantité
    PMP
    Value
    Quantité
    PMP
    Value
    01.01.2014
    Intial Stock
    2000
    11
    22000
    16.01.2014
    Purchase Order 1
    10000
    10
    100000
    2000
    11
    22000
    12000
    10,17
    122040
    20.01.2014
    Good issue
    2000
    20340
    10,17
    12000
    10,17
    122040
    10000
    10,17
    101700
    18.02.2014
    Purchase Order 2
    20000
    9
    180000
    10000
    10,17
    101700
    30000
    9,44
    283200
    22.02.2014
    Good issue
    22000
    9,44
    207680
    30000
    9,44
    283200
    8000
    9,44
    75520
    30.03.2014
    Purchase Order 1
    10000
    9,5
    95000
    8000
    9,44
    75520
    8000
    9,28
    74240
    21.04.2014
    Good issue
    2000
    9,28
    18560
    8000
    9,28
    74240
    6000
    9,28
    55680
    31.05.2014
    Purchase Order 2
    20000
    7
    140000
    6000
    9,28
    55680
    6000
    8,03
    48180
    - When the first invoice is recorded, SAP should calculate the MAP this way: (2000*11+10000*9,5+20000*9)/(2000+10000+20000) = 9,28
    - When the second inoice is recorded, SAP should calculate the MAP this way: (2000*11+10000*9,5+20000*7)/(2000+10000+20000) = 8,03
    Could you tell me if you know how to set up the calculation based on this formula (Intial stock value at MAP + Year to date Purchasing value) divided by (intial stock quantity + quantity purchased)?
    Thank you in advance
    Regards

    Arti,
    MBEWH table will get you the MAP of a material monthwise,I guess you need to get the logic which will use those details to arrive on MAP for a paritcular date.
    Check the SDN Forums with the keyword "MOVING AVERAGE PRICE REPORT" to get some lead.
    moving average price report
    K.Kiran.

  • Date calculations based on working days

    I need to add date calculations to a worksheet to show the time elapsed between two actions.
    Just a straightforward subtraction works fine, but what I really need to be able to do is calculate the number of working days between the two point (as something taking 5 days over Christmas with the 2 bank holidays is different equivalent to something taking 3 days in a normal week)
    At the moment I'm exporting the data into excel for analysis of this, but would really like to be able to do it in Disco so that the end users can go straight to the report using viewer, rather than having to do the conversion for them.
    Is this possible?
    Cheers

    Hi,
    Every thing is possible, the Q is how complicated is it....
    My suggestion is to create a table with all the dates of the non-working days for ex:
    create a table with all the MON-THURSDAYS, union to this table the holidays you know of such as christmas and so on.
    After getting this table you can create a function that returns the number of working days between 1 date to another by subtracting the days exists in this table.
    I started with that, you are more then welcome to get ahead with it and let us know what happened...
    create table holiday
    D_date date,
    d_day varchar2(20)
    create or replace procedure holiday_proc is
    d_date date;
    begin
    d_date := trunc(sysdate);
    while d_date<'01-jan-2010'
    loop
    if to_char(trunc(d_date),'Day') not in ('Saturday ','Sunday ') then
    INSERT INTO Holiday (d_date,d_day)
    (select trunc(d_date),to_char(trunc(d_date),'Day') from dual);
    end if;
    d_date := d_date+1;
    end loop;
    commit;
    end holiday_proc;

  • Seeking a Current Age calculation based upon b'day

    I'm seeking a Current Age calc based upon birthday and a set date in the future (5-5-2012) for a registration form.  I have zero Java or FormCalc background.  I'm using LiveCycle Designer 8.0 for the first time.  Any assistance would be appreciated.

    Thank you radzmar, sadly I do not know where to enter the formula you suggested.  I found a page that mentions FormCalc (Form Properties / Default tab under the File menu option).  My novice skills are not up to this challenge apparently.  ;- (
    I changed the field to a text field with Optional user input.  I’ll have to buy a book and read up.  ;- )

  • Query! calculation based on previous row value

    Hi,
    ID     Code     Direction     From Amount  To Perct      To Amount
    98     POI     F          5457.00          0     
    77     LKJ     T          0          50      (5457*(50/100))
    56     MNB     T          0          25      (5457*(25/100))How to calculate 'To Amount' with in the select query? To Amount will be calculated on the basis of
    From Amount of the First row multiplied by 'To Perct'
    When I wrote a select statement it's taking 0 as 'From Amount'( Because it's in current row) and giving me 0 as 'To Amount'
    Thanks

    One possibility:
    with t as (
    select 98 id,     'POI' Code,     'F' Direction, 5457.00 FromAmount,          0 ToPerct from dual     union all
    select 77,     'LKJ',     'T',          0,          50 from dual     union all
    select 56,     'MNB',     'T',          0,          25 from dual)
    select id, code, direction, FromAmount, ToPerct,
           (tmax.MaxAmount)*(ToPerct/100) ToAmount 
    from t,
         (select max(FromAmount) MaxAmount from t) tmax ;Results:
            ID COD D FROMAMOUNT    TOPERCT   TOAMOUNT
            98 POI F       5457          0          0
            77 LKJ T          0         50     2728,5
            56 MNB T          0         25    1364,25Regards,
    Miguel

  • Current day "shift starts from previous day" night 23:00 hours

    Hi Experts,
    I have a challenging scenario in Positive Time Management which is current day 1st shift time starts from previous day 23:00 hours (eg: previous day 23:00 to 07:00 current day).
    As per my knowledge in SAP Time Management, Shift start time is considered as current day, but for my scenario Shift End time has to consider as a current day.
    I couldnu2019t brought this shift forward to as 3rd shift because Production Incentives amounts and public holidays are computing based on previous day 23:00 hours.
    Points will be awarded for helpful solution.
    Regards
    Raju

    While you create a recod in the IT 2011 as you give
    next field you wil be having a field for previous day option if you choose that
    p20 for out time
    ex: 7:00 am i.e next day but still it will count for the current day
    Best Regards

  • Calculation of due date based on Business Days for FICA documents

    Hi All,
    I am working on project where SD - FICA integration is in picture. We post some charges through SD and FICA document gets posted on relevant Contract Account.
    Normally we create Sales Order using transaction VA01 and then we do Billing for this Sales Order through VF01. After billng is done, FICA document automatically gets generated.
    We have following requirement to be fulfilled.
    For the SD bills posted as above, I want to calculate due date of these bills based on Business Days for FICA document generated (SAP Standard calculate due date based on Calander days). We can use factory calander for calculating business days in relevant function module.
    I have checked in the system and it seems that event 1330 ( FM - ISU_DUE_DATE_DETERMINE) is not working in this scenario. Is there any other FM which I can use?
    Can anyone help me on this?
    Regards,
    Pradeep

    Hello Praeva ,
    The event 1330 has a sample FM FKK_SAMPLE_1330. It doesnt even have a Standard Function Module.
    You need to create a Installation-Specific FM and put your code to determine the Due Date based on the logic.
    Rgds
    Ram Kumar.

  • Calculation based on date key figures in BEx

    Hi Friends,
    Hi Friends,
    I need to creat report for sales order data, which involved the calculation based on dates.
    In my cune iam having the data at the granual level with the dates as key figures. the calculation that i need to do is VTW = Actual PGI date - Customer want date.
    1) whn i run the report at the granual level my VTW is working correctly. No issues.
    2) when i run the report at higher levels the date fields are updated with X, as the system is unable to aggrigate the dates. The dates are at the material level in  a sales order. I need to show the VTW at the sales order level (each one of the two dates are same for all the materials). So, when i run the report with out mataril at the sales order level...i wanto sea the bothe date fields in a single line and also the VTW calculated as the different between throse two dates.
    3) Once we get the VTW correctly at the sales orde level. if i drill down the report for material, i want to sea both the dates in every record againest the matarial, but the VTW only aginest the first record...that is againest the sales order. I dont waht the VTW value repeated/duplicated for all the records againest the sales order,as VTW makes sence only at the Sales Order level.
    Please suggest me hwo i can achive the resulsts by meeting both Point 2 and 3.
    Thanks for ur help...in advance.
    Thanks,
    Renu

    Hi..
    I have the data from the extractore and in the cube as below.
    SALES ORDER    ITEM                MATERIAL            DATE1                         DATE2
    101                        Item1               Mat1              01/01/2010                15/01/2010
    101                        Item2               Mat2              01/01/2010                15/01/2010
    101                       Item3                Mat3             01/01/2010                15/01/2010
    I need the reports as below...
    Report1:
    SALES ORDER        DATE1                         DATE2                  VTW (DATE2 - DATE1)
    101                        01/01/2010                15/01/2010                14
    currently iam getting this Report1 output as below...
    SALES ORDER        DATE1                         DATE2                  VTW (DATE2 - DATE1)
    101                             X                                   X                           42
    Report2: Out put required as below
    SALES ORDER     ITEM                MATERIAL            DATE1                         DATE2      VTW (DATE2 - DATE1)
    101                        Item1               Mat1              01/01/2010                15/01/2010              14
    101                        Item2               Mat2              01/01/2010                15/01/2010
    101                   I     tem3                Mat3             01/01/2010                15/01/2010
    currently iam getting this Report2 output as below...
    SALES ORDER     ITEM                MATERIAL            DATE1                         DATE2      VTW (DATE2 - DATE1)
    101                        Item1               Mat1              01/01/2010                15/01/2010              14
    101                        Item2               Mat2              01/01/2010                15/01/2010               14
    101                   I     tem3                Mat3             01/01/2010                15/01/2010               14
    As VTW is need to be measued at the sales order level and we always have the DATE1 & DATE2 as same for all the itesm, it should be shon as only 14 in the first record. It mean once iget the required output from Report one in a single line with VTW as 14, it should not repeat with every line , when i dril down the report for Items or materials.
    Even if i can generate oly report2 as required in a single sheet ...that will be enough.
    Plas kindly provide some solution as how we can achieve this,
    Thanks,
    Renu

  • Previous days data based on passing parameter and date

    Hi,
    i have one rek..that requirement to to show the previous days data based on the number passing to the parameter parameter.
    lets suppose if user enters the date '25 Mar 2012 in one dashboard prompt and in another prompt user enters the no.of days(Ex: 5).then report should display the last 5 days data i.e 25 mar 2012,24 mar 2012,23 mar 2012,22 mar 2012,21 mar 2012.
    can anybody tell me how can i achieve this..
    Thanks in advance...

    user12255470 wrote:
    Hi,
    i have one rek..that requirement to to show the previous days data based on the number passing to the parameter parameter.
    lets suppose if user enters the date '25 Mar 2012 in one dashboard prompt and in another prompt user enters the no.of days(Ex: 5).then report should display the last 5 days data i.e 25 mar 2012,24 mar 2012,23 mar 2012,22 mar 2012,21 mar 2012.
    can anybody tell me how can i achieve this..
    Thanks in advance...Read the article and adapt it to what you are doing. It's very similar...
    http://oraclebizint.wordpress.com/2008/03/11/oracle-bi-ee-101332-rolling-yearmonth-and-date-filters-moving-window-filters/

  • Factoring based on 26 days

    Hi friends
    The client requirement is to calculate payroll based on 26 days flat.  I am sure we will face issues in the month of February where we have only 24 working days and month like March(27 days), April(25 days), May(27 days) and August(27 days). Could anyone please adivse me on the possibile problems which can occur if we go for this.  Would like to understand the scenarios in case if some employees leaves or joins in the middle of the month and what would be the payroll calculation.
    Friends please help.
    Santhosh.S

    Hi
    Could you please help me with an example like if the employee join on 12th Feb what would be his salary for that month likewise if an employee resigns in the month of March. 
    Regards
    Santhosh.S

  • How to set the payment Due date calculation as per working days.

    how to make changes in the vendor Payment terms so that while calculating the Payment due date as per Payment terms, system calculates it based on Working Days & not the Calender days ?
    Help is much appriciated.
    Thank you,
    Amit

    Hi,
    This is the standard settings by SAP, normally we couldn't change it to working day.
    Good luck
    Tao

  • Calculation based on radio box Help PLEASE....

    I am trying to make a text box perform a calculation based on whether or not a radio button is checked or not.
    If the radio button named "Basting" in the "Quilting Type" group is checked then the text box "Basting Charge" should find the value of the "Total Square Inches" field and  multiply that total by 0.015 and show the new total in the text box as a dollar value, if the radio button "Basting" is not checked the value in the "Basting Charge" field should be "-0-".
    I can get the calculation I want from this:
    var v1 = getField("Total Square Inches").value; event.value=v1*0.015;
    but how to include the radio button function and the "-0-" ?

    Okay, I have now made a "check box" with the name of "Basting", not in a grouping.
    This is the set up:
    Text Field = Total Square Inches
    Check Box = Basting
                                       Export Value = Yes
    Text Field = Basting Charge
    Calculation for "Basting Charge" should be "0" unless the "Basting" check box is used, then it should get the value of the "Total Square Inches" and multiply that number by 0.015 and show this value in the "Basting Charge" box displaying as a dollar figure.
    So if the value in the "Total Square Inches" is 12,000
    and the "Basting" check box is used
    The "Basting Charge" should read "$180.00"
    if the check box is not used then it should read "-0-"

  • Report is not displaying 'previous day maximum sale' correctly

    There is a issue in the report
    Based on material and date and displays the previous day maximum sale
    The issue is whenever i run the report in give a single Document Date on selection screen it works fine but whenever i run the report in a range it shows the previous date of the range like when i run the report with
    Document date - 05.07.2007, its working fine but and showing 04.07.2007 as previous day
    when run the report
    Document date - 01.07.2007 to 31.07.2007, its displaying 30.07.2007 for all records and not displaying different results based on doc date,
    like it should show for      31.07.2007 --- 30.07.2007 and
                                   30.07.2007 --- 29.07.2007
                                  29.07.2007 --- 28.07.2007     
    CODE :-
    FORM data_retrieval.
    SELECT MSEGMATNR MSEGMBLNR MSEGMENGE MSEGMEINS MSEGCHARG MSEGLGORT MSEGBWART MSEGWERKS MSEGLIFNR MSEGEBELN MSEGBPRME MSEGDMBTR MSEGEXBWR MSEGVKWRT MSEG~SHKZG
           MKPFBLDAT MKPFBUDAT MKPFMBLNR MKPFBKTXT MKPFXABLN MKPFCPUDT MKPFXBLNR MKPFMJAHR
      INTO CORRESPONDING FIELDS OF TABLE itab FROM MSEG
    JOIN MKPF
    ON  MSEGMBLNR = MKPFMBLNR
    where MSEG~MATNR IN S_MATNR
    AND MSEG~WERKS IN S_WERKS
    AND MSEG~LGORT IN S_LGORT
    AND MSEG~CHARG IN S_CHARG
    AND MSEG~LIFNR IN S_LIFNR
    AND MSEG~KUNNR IN S_KUNNR
    AND MSEG~BWART IN S_BWART
    AND MSEG~SOBKZ IN S_SOBKZ
    AND MKPF~BUDAT IN S_BUDAT
    AND MKPF~BLDAT IN S_BLDAT     .
    IF ITAB[] IS NOT INITIAL.
    select matnr vbeln netwr UMKZWI1_01 fkdat ummenge VKORG VGBEL from s961
      into corresponding fields of table IT_S961 FOR ALL ENTRIES IN itab
    where matnr = itab-matnr and fkdat < itab-bldat.
    ENDIF.
    SORT IT_S961 descending BY matnr fkdat ummenge .
      LOOP AT itab INTO wa_itab.
        READ TABLE IT_S961 WITH KEY MATNR = WA_ITAB-MATNR BINARY SEARCH.
        IF sy-subrc = 0.
        wa_itab-VBELN = IT_S961-VBELN.
        wa_itab-NETWR = IT_S961-NETWR.
        wa_itab-UMKZWI1_01 = IT_S961-UMKZWI1_01.
        wa_itab-UMMENGE = IT_S961-UMMENGE.
        wa_itab-VKORG = IT_S961-VKORG.
        wa_itab-VGBEL = IT_S961-VGBEL.
        wa_itab-FKDAT = IT_S961-FKDAT.
        ENDIF.
        MODIFY itab FROM wa_itab TRANSPORTING VBELN NETWR UMKZWI1_01 FKDAT UMMENGE VKORG VGBEL.
        CLEAR : wa_itab.
    ENDLOOP.

    Hi,
    Still values are not coming
    SELECT matnr fkdat ummenge vbeln vkorg vgbel netwr umkzwi1_01 FROM s961
       INTO CORRESPONDING FIELDS OF TABLE it_s961 FOR ALL ENTRIES IN itab
        WHERE matnr = itab-matnr
        AND fkdat EQ itab-previous_dt.
    ENDIF.
      sort it_s961 by matnr vbeln fkdat previous_dt ummenge descending .
      LOOP AT itab INTO wa_itab.
        READ TABLE it_s961 WITH KEY matnr = wa_itab-matnr BINARY SEARCH.
        IF sy-subrc = 0.
          wa_itab-vbeln = it_s961-vbeln.
          wa_itab-netwr = it_s961-netwr.
          wa_itab-umkzwi1_01 = it_s961-umkzwi1_01.
          wa_itab-ummenge = it_s961-ummenge.
          wa_itab-vkorg = it_s961-vkorg.
          wa_itab-vgbel = it_s961-vgbel.
          wa_itab-fkdat = it_s961-fkdat.
        ENDIF.
        MODIFY itab FROM wa_itab TRANSPORTING fkdat ummenge vbeln netwr umkzwi1_01 vkorg vgbel.
        CLEAR : wa_itab.
      ENDLOOP.

  • Find Previous Day From a Given Day

    Hey guys, I'm new here and I just recently started working with Java, I am trying to figure out how to find the previous day for the 1st day and month of a year_. I.E. if passed the date (1,1,2000) in the mm/dd/yyyy format then the output would be (12,31,1999). I have everything worked out except I have to figure out how to find the last day of the previous month. I am trying to write this all from scratch to better understand Java, so i do not want to use the Calendar class or anything involved with it.
    This is a handful of code that may not be formatted a bit sloppily, but if anyone has the time, I would greatly appreciate the help. (Also, I am aware that Java autmatically puts "this." if it is missing before a variable, I put mine in order to clearly see what's going on.) I made a test Class as well is anyone is interested in seeing it.
    Also, how come the Java formatting does not show in the post?
    * Date calculates the date and gives other information requested such as the birthday of someone, the
    * previous and next days, whether the date is valid or not, and whether the year is a leap year
    * @author Vlad Khmarsky
    * @version 1.1
    public class Date
    /** The month */
    int month = 00;
    /** The day */
    int day = 00;
    /** The year */
    int year = 0000;
    /** First month of the year */
    int firstMonth = 1;
    /** Last month of the year */
    int lastMonth = 12;
    /** Asks for the day, month, and year upon creting an instance of dates
    * @day asks for the day
    * @month asks for the month
    * @year asks for the year
    Date( int month_, int day_, int year_) {
    this.month = month_;
    this.day = day_;
    this.year = year_;
    /** Gets the month passed in initially
    * @return The month that is currently stored in the month field
    int getMonth() {
    return this.month;
    /** Gets the day passed in initially
    * @return The day that is currently stored in the month field
    int getDay() {
    return this.day;
    /** Gets the year passed in initially
    * @return The year that is currently stored in the month field
    int getYear() {
    return this.year;
    /** Gets the number of days in the given month
    * @return the number of days in the given month
    int getDaysInTheMonth() {
    return this.daysInTheMonth();
    /** Returns the date in Gregorian format
    * @return Returns the date in Gregorian format
    * Test Cases:
    * this.Dates(12, 10, 1989) = "12/10/1989"
    * this.Dates(54, 67, 9999) = "54/67/9999"
    * this.Dates(-1, -9, -900) = "-1/-9/-900"
    String toPrettyString() {
    return month + "/" + day + "/" + year;
    /** Checks whether the passed in date is valid or not
    * @return A true or false whether the date is valid
    * Test Cases:
    * this.Dates(12, 10, 1989) = true
    * this.Dates(54, 67, 9999) = false
    * this.Dates(-1, -9, -900) = false
    boolean isValid() {
    if (this.getDay() >= 0
    && this.getDay() <= 31
    && this.getMonth() >= 0
    && this.getMonth() <= 12) {
    return true;
    else {
    return false;
    /** Calculates the age of a person given the date
    * @return The age of the person
    * Test Cases:
    * this.Dates(12, 10, 1990), dateMarked.Dates(12, 10, 0) = 1990
    * this.Dates( 4, 25, 1000), dateMarked.Dates(12, 10, -990) = 1990
    * this.Dates( 1, 1, 2578), dateMarked.Dates(12, 10, 1989) = 589
    int calculateAge( Date birthday ) {
    return (this.getYear() - birthday.getYear());
    /** Do two dates represent the exact same day?
    * @param other The date to compare this Date against.
    * @return true if (and only if) this Date represents the same day as other.
    * (that is, the same year, month, day-of-month).
    * Test Cases:
    * this.Dates(12, 10, 1989), other.Dates(12, 10, 1989) = true
    * this.Dates(12, 10, 1989), other.Dates(11, 10, 1989) = false
    * this.Dates(12, 10, 1989), other.Dates(12, 9, 1989) = false
    * this.Dates(12, 10, 1989), other.Dates(12, 10, 1988) = false
    boolean isEqualTo( Date otherDate ) {
    if (this.getDay() == otherDate.getDay()
    && this.getMonth() == otherDate.getMonth()
    && this.getYear() == otherDate.getYear()) {
    return true;
    else {
    return false;
    /** Does one Date precede another?
    * @param other The date to compare this Date against.
    * @return true if (and only if) this Date comes before other.
    * this.Dates( 5, 5, 2000), other.Dates( 5, 6, 2000) = true
    * this.Dates( 5, 5, 2000), other.Dates( 6, 5, 2000) = true
    * this.Dates( 5, 5, 2000), other.Dates( 5, 5, 2001) = true
    * this.Dates( 5, 5, 2000), other.Dates( 5, 4, 2000) = false
    * this.Dates( 5, 5, 2000), other.Dates( 5, 5, 1999) = false
    * this.Dates( 5, 5, 2000), other.Dates( 4, 5, 2000) = false
    boolean isBefore( Date otherDate ) {
    if (this.getYear() <= otherDate.getYear()
    && this.getMonth() <= otherDate.getMonth()
    && this.getDay() < otherDate.getDay()) {
    return true;
    else if (this.getYear() <= otherDate.getYear()
    && this.getMonth() < otherDate.getMonth()) {
    return true;
    else if (this.getYear() < otherDate.getYear()) {
    return true;
    else {
    return false;
    /** Determines how many days there are in the month, given the instance's specified month and year
    * @Return returns the number of days in the month
    int daysInTheMonth () {
    if (this.isValid() == true) {
    if (this.getMonth() == 2) {
    if (this.isLeapYear() == true) {
    return 29;
    else {
    return 28;
    else if (this.getMonth() == 1
    || this.getMonth() == 3
    || this.getMonth() == 5
    || this.getMonth() == 7
    || this.getMonth() == 8
    || this.getMonth() == 10
    || this.getMonth() == 12) {
    return 31;
    else {
    return 30;
    else {
    return 0;
    /** Return the day after `this`. (`this` must be a valid date.)
    * @return the day after `this`. The result will be valid if `this` is valid.
    Date nextDay() {
    if (this.getDay() == this.getDaysInTheMonth() && this.getMonth() == 12) {
    return new Date(1, 1, this.getYear() + 1);
    else if (this.getDay() == this.getDaysInTheMonth()) {
    return new Date(this.getMonth() + 1, 1, this.getYear());
    else {
    return new Date(this.getMonth(), this.getDay() + 1, this.getYear());
    /** Return the day before `this`. (`this` must be a valid date.)
    * @return the day before `this`. The result will be valid if `this` is valid.
    Date previousDay() {
    if (this.getDay() == 1 && this.getMonth() == 1) {
    return new Date(12, this.getDaysInTheMonth(), this.getYear() - 1);
    //Need to fix the days in the previous month and previous month
    else if (this.getDay() == 1) {
    return new Date(this.getMonth() - 1, this.getDaysInTheMonth() - 1,
    this.getYear()); //need to fix the days in the previous month
    else {
    return new Date(this.getMonth() - 1, this.getDaysInTheMonth(), this.getYear());
    /** Returns a true or false depending on whether the year is a leap year or not
    * @return a true or false depending on whether the year is a leap year or not
    * Test Cases:
    * this.Dates( 5, 5, 2000) = true
    * this.Dates(12, 6, 2004) = true
    * this.Dates( 1, 1, 2001) = false
    * this.Dates( 7, 9, 2006) = false
    boolean isLeapYear () {
    if (this.getYear() % 400 == 0) {
    return true;
    else if (this.getYear() % 100 == 0) {
    return false;
    else if (this.getYear() % 4 ==0) {
    return true;
    else {
    return false;
    null
    Edited by: THE_Russian on Sep 28, 2007 4:35 PM

    Yeahhhh... that's exactly what I was trying not to do, I know that method, I don't want any associations with the Calendar class, thanks though
    Aw crap, you can't edit the original post? Sorry everyone for the unformatted code, here's the formatted version
    * Date calculates the date and gives other information requested such as the birthday of someone, the
    *  previous and next days, whether the date is valid or not, and whether the year is a leap year
    * @author Vlad Khmarsky
    * @version 1.1
    public class Date
    /** The month */
        int month = 00;
    /** The day */
        int day = 00;
    /** The year */
        int year = 0000;
    /** First month of the year */
        int firstMonthInYear = 1;
    /** Last month of the year */
        int lastMonthInYear = 12;
    /** First day of the month */
        int firstDayInMonth = 1;
    /** Asks for the day, month, and year upon creting an instance of dates
       * @day asks for the day
       * @month asks for the month
       * @year asks for the year
        Date( int month_, int day_, int year_) {
            this.month = month_;
            this.day = day_;
            this.year = year_;
    /** Gets the month passed in initially
       * @return The month that is currently stored in the month field
        int getMonth() {
            return this.month;
    /** Gets the day passed in initially
       * @return The day that is currently stored in the month field
        int getDay() {
            return this.day;
    /** Gets the year passed in initially
       * @return The year that is currently stored in the month field
        int getYear() {
            return this.year;
    /** Gets the number of days in the given month
       * @return the number of days in the given month
        int getDaysInTheMonth() {
            return this.daysInTheMonth();
    /** Returns the date in Gregorian format
       * @return Returns the date in Gregorian format
       * Test Cases:
       *    this.Dates(12, 10, 1989) = "12/10/1989"
       *    this.Dates(54, 67, 9999) = "54/67/9999"
       *    this.Dates(-1, -9, -900) = "-1/-9/-900"
        String toPrettyString() {
            return month + "/" + day + "/" + year;
    /** Checks whether the passed in date is valid or not
       * @return A true or false whether the date is valid
       * Test Cases:
       *    this.Dates(12, 10, 1989) = true
       *    this.Dates(54, 67, 9999) = false
       *    this.Dates(-1, -9, -900) = false
        boolean isValid() {
            if (this.getDay() >= 0
                && this.getDay() <= 31
                && this.getMonth() >= 0
                && this.getMonth() <= 12) {
                return true;
            else {
                return false;
    /** Calculates the age of a person given the date
       * @return The age of the person
       * Test Cases:
       *    this.Dates(12, 10, 1990), dateMarked.Dates(12, 10,    0) = 1990
       *    this.Dates( 4, 25, 1000), dateMarked.Dates(12, 10, -990) = 1990
       *    this.Dates( 1,  1, 2578), dateMarked.Dates(12, 10, 1989) =  589
        int calculateAge( Date birthday ) {
            return (this.getYear() - birthday.getYear());
    /** Do two dates represent the exact same day?
       * @param other The date to compare this Date against.
       * @return true if (and only if) this Date represents the same day as other.
       *  (that is, the same year, month, day-of-month).
       *  Test Cases:
       *    this.Dates(12, 10, 1989), other.Dates(12, 10, 1989) = true
       *    this.Dates(12, 10, 1989), other.Dates(11, 10, 1989) = false
       *    this.Dates(12, 10, 1989), other.Dates(12,  9, 1989) = false
       *    this.Dates(12, 10, 1989), other.Dates(12, 10, 1988) = false
        boolean isEqualTo( Date otherDate ) {
            if (this.getDay() == otherDate.getDay()
                && this.getMonth() == otherDate.getMonth()
                && this.getYear() == otherDate.getYear()) {
                return true;
            else {
                return false;
    /** Does one Date precede another?
       * @param other The date to compare this Date against.
       * @return true if (and only if) this Date comes before other.
       *    this.Dates( 5,  5, 2000), other.Dates( 5,  6, 2000) = true
       *    this.Dates( 5,  5, 2000), other.Dates( 6,  5, 2000) = true
       *    this.Dates( 5,  5, 2000), other.Dates( 5,  5, 2001) = true
       *    this.Dates( 5,  5, 2000), other.Dates( 5,  4, 2000) = false
       *    this.Dates( 5,  5, 2000), other.Dates( 5,  5, 1999) = false
       *    this.Dates( 5,  5, 2000), other.Dates( 4,  5, 2000) = false
        boolean isBefore( Date otherDate ) {
            if (this.getYear() <= otherDate.getYear()
                && this.getMonth() <= otherDate.getMonth()
                && this.getDay() < otherDate.getDay()) {
                return true;
            else if (this.getYear() <= otherDate.getYear()
                && this.getMonth() < otherDate.getMonth()) {
                return true;
            else if (this.getYear() < otherDate.getYear()) {
                return true;
            else {
                return false;
    /** Determines how many days there are in the month, given the instance's specified month and year
       * @Return returns the number of days in the month
        int daysInTheMonth () {
            if (this.isValid() == true) {
                if (this.getMonth() == 2) {
                    if (this.isLeapYear() == true) {
                        return 29;
                    else {
                        return 28;
                else if (this.getMonth() == 1
                         || this.getMonth() == 3
                         || this.getMonth() == 5
                         || this.getMonth() == 7
                         || this.getMonth() == 8
                         || this.getMonth() == 10
                         || this.getMonth() == 12) {
                    return 31;
                else {
                    return 30;
            else {
                return 0;
    /** Return the day after `this`.  (`this` must be a valid date.)
       * @return the day after `this`.  The result will be valid if `this` is valid.
      Date nextDay() {
          if (this.getDay() == this.getDaysInTheMonth() && this.getMonth() == 12) {
              return new Date(firstMonthInYear, firstDayInMonth, this.getYear() + 1);
          else if (this.getDay() == this.getDaysInTheMonth()) {
              return new Date(this.getMonth() + 1, firstDayInMonth, this.getYear());
          else {
              return new Date(this.getMonth(), this.getDay() + 1, this.getYear());
    /** Return the day before `this`.  (`this` must be a valid date.)
       * @return the day before `this`.  The result will be valid if `this` is valid.
      Date previousDay() {
          if (this.getDay() == 1 && this.getMonth() == 1) {
              return new Date(lastMonthInYear, this.getDaysInTheMonth(), this.getYear() - 1); //Need to fix the days in the previous month and previous month
          else if (this.getDay() == 1) {
              return new Date(this.getMonth() - 1, this.getDaysInTheMonth() - 1, this.getYear()); //need to fix the days in the previous month
          else {
              return new Date(this.getMonth() - 1, this.getDaysInTheMonth(), this.getYear());
    /** Returns a true or false depending on whether the year is a leap year or not
       * @return a true or false depending on whether the year is a leap year or not
       * Test Cases:
       *    this.Dates( 5,  5, 2000) = true
       *    this.Dates(12,  6, 2004) = true
       *    this.Dates( 1,  1, 2001) = false
       *    this.Dates( 7,  9, 2006) = false
        boolean isLeapYear () {
            if (this.getYear() % 400 == 0) {
                return true;
            else if (this.getYear() % 100 == 0) {
                return false;
            else if (this.getYear() % 4 ==0) {
                return true;
            else {
                return false;
    }null

Maybe you are looking for

  • How do I stop contacts updating across two phones?

    Hi This is my first post, so please treat me gently My partner and me have both just got 3g iphones, we love them but have one slight prob with them. When we connect our phones to our itunes account, contact details from both phones are replaced with

  • Virtual terminal problems (konsole, lxterminal)

    Hi, I did not find the solution for my particular problem, where the virtual terminal can't connect to the bash execution. I'm using arch linux including all repos [testing, community-testing], and after a update, I'm unable to run konsole or lxtermi

  • Ask for help! I am new for JWSDP

    After I run the jwsdp-1_4-windows-i586.exe program and installed the Java WSDP 1.4 sucessfully, I can't find the examples directory under the <JWSDP_HOME>/docs/tutorial folder, Why? How can I get the examples? In the addition, I try to integrate JWSD

  • Mini Bridge CS6 nav pod needs sorting

    How can I resort the folders shown in the Navigation Pod of Mini Bridge in InDesign CS6? They seem to be in a completely random order, and I would at least like to see them in conventional alphanumeric order. I have no problem re-sorting the content

  • Saving files after PS

    When I send a file to Ps from Lr, edit that file then save it, Lr puts that file at the end of the line instead of next to the file I was working on.  When you have 600 photos in a down loud, it is a pain to scroll through the photo's to find your pl