Calculation of days base on dates

I have an input of date through 3 jcombo box captured in string denoting dd/mm/yyyy.
I need to compute the two dates entered into the system a derive the number of days.
Please advise how I could do that.

import java.util.Calendar;
public long numberOfDay(int year1,int month1,int day1,int year2,int month2,int day2)
          Calendar cal1=Calendar.getInstance();
          cal1.set(year1,month1,day1);
          Calendar cal2=Calendar.getInstance();
          cal2.set(year2,month2,day2);
          long ms=0;
          if(cal1.before(cal2))
               ms=cal2.getTime().getTime()-cal1.getTime().getTime();
          else
               ms=cal1.getTime().getTime()-cal2.getTime().getTime();
          long s=ms/1000;
          long m=s/60;
          long h=m/60;
          return h/24;    
}You could use this, before to make your string, or change on regarding the Callendar class
JHelp

Similar Messages

  • Calculating Business Days in a Date Range

    I have two questions:
    1. Does anyone know a better formula for calculating business days in totals?
    I am currently using the formula in https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/701a52c3-6b1e-2b10-21b3-a6e101be1a0f
    I tailored to my needs.  However, there are still a lot of manual maintenance every year. 
    2. I have many reports that need the formula.  It is very consuming to update the formula in each report.  Does anyone know a better way to do it? 
    I use Crystal XI. 11.0.0.895.  We do have a Crystal Enterprise server hosted in another department.

    Not sure if this is any simpler but you could save this as a custom function, that way you will have to modify it once a year for the holidays.
    numbervar days;
    datevar date1 := minimum({?My Parameter});
    datevar date2 := maximum({?My Parameter});
    days := DateDiff ("d", date1, date2) -
    DateDiff ("ww", date1, date2, crSaturday) -
    DateDiff ("ww", date1, date2, crSunday);    // this will give you the number of business days
                                                        // (excluding Saturdays and Sundays) for a given date range.
    // then, for each holiday, you can enter lines like this
    if date(2008,01,01) in {?My Parameter} then days := days - 1;
    // The final tally of DAYS should give you the total business days in a date range.
    totext(days,0);
    where {?My Parameter} is the date range.

  • Simple date calculation: add days to a date

    Hi,
    I'm looking for a function module in APO that can simply add a number of days to a date.
    I know I can code (date + days) but would rather a module if possible.
    Thks,
    William

    I know FM /SAPAPO/MSDP_SNPHEU_DAYS_ADD is used in SNP ... but not sure it is suitable for you.

  • Date Calculations on 360 days basis (30 days a month)

    Does any body know how to get
    difference between 2 dates on 360 days basis i.e 30 Days a month

    Please ignore the previous post.
    cal.set(DAY_OF_YEAR,360);
    is used the set the current day of the year to 360, not the total number of days in year. The same goes with
    cal.set(DAY_OF_MONTH,30);
    which sets the current day of the month to 30.

  • Due date falls on 80 days from base line date ........but end of that month

    Hi All
    Can any one please guide me in creating a payment term
    The Base Line Date would be 80 days from Posting date ........... But end of that month
    Example
    Posting date 01.01.2009 so the base line date would be on 21st March
    01.01 ;          31.01 ;                            31 Days
    01.02 ;          28.02 ;                            28 Days
    01.03 ;          21.03 ;                            21 Days               80 Days              
    But due date should fall on end of that month 31st of march
    So irrespective of any day calculated as above in that month  it will always take the baseline date as last day of the month    
    Its Picking up the posting day as Baseline date from Transaction VA01 -> Additional data tab -> ETD ( Festinated Time of Departure)
    From this date it need to calculate the due date as above ( 80 day but last day of the month)
    Please Guide
    Many thanks in advance
    Aadi

    Hi Aditya,
    You may have to create 2 payment terms using the day limit option to meet this requirement.
    Follows the below steps -
    T-code OBB8
    Term 1
    Payment terms = xxxx (as you wish)
    Day limit = any number between 10-15 (you may fix an appropriate date as you think fit for your business)
    Default for baseline date = Posting date
    Payment terms/fixed date = 31
    Payment terms/additional months = 2
    Term 2
    Payment terms = same name as above
    Day limit = 31
    Default for baseline date = Posting date
    Payment terms/fixed date = 31
    Payment terms/additional months = 3
    Logic here is... for all invoices with posting date on or before 10th-15th of a month, 80th day will fall definitely on the 2nd month. Invoices with posting date after 15th, the 80th day will fall on the 3rd month.
    You have to take a concious decision on the day limit number. Because 80 days will not exactly work for all the months.
    Regards,
    Mike

  • Setting Payment terms in PO linking to base line date for payables.

    Hi
    can some help me by giving me simple  steps to create  the payment terms which will be captured in PO and payment is made with reference to baseline date.
    Example :
    1. payment in 15 days from the date of GRN posting date. while doing MIRO, the base line date will be proposed 15 days from the date of GRN posting date.
    2. payment in 30 days from the date of GRN posting date. while doing MIRO, the base line date will be proposed 30 days from the date of GRN posting date.
    while doing MIRO, the base line date will be
    rgds
    Raghu

    Hi
    There is no link between GRN posting date and proposed base line date for payment in MIRO. All that you can link is the posting date/ document date in MIRO etc with base line date calculation in invoice.
    Create a new payment term with posting date (the current date will be defaulated as posting date in MIRO always) and with some payment discount terms say after 15 days etc..
    Thanks

  • Base line date in invoice

    Hi
    In configuration settings I have maintained the following for a payment term:
    Baseline date calculation :Fixed day - 0
                                          Additional months - 0
    default for baseline date - document date
    payment terms as 30 days net from invoice date.
    Now for an invoice dated 28/01/2008 with posting date 31/01/2008, baseline date is appearing as 28/02/2008 (one month from invoice date) and payment due date is 29/03/2008 (one month from base line date).
    Please explain why is the system picking wrong baseline and payment due dates.
    Thanks
    Prasad

    Dear Mathu,
    1)Your base line date calculation - Fixed day - 0
    2) default for baseline date  is  document date
    3 payment terms as 30 days net from invoice date
    Being invoice date is 28 / 1/ 08 payment date will be 30 days after this days i.e. 28 / 2 /08.
    Reward if its cleared your doubt
    Vivek Maitra

  • Query on fetching the no.of days between Invoice date and due date in rtf template embedded BI Publisher Report

    Hi Experts,
    We have a requirement to fetch the value of 'No of days' between Invoice date and due date (Two variable date fields on the template) in an Analysis.
    Please let me know the procedure of how to achieve the same.
    Regards,
    Rev

    it's good for ideas but implementation a bit different
    Oracle Business Intelligence Publisher Report Designer's Guide
    This function provides a method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only the Gregorian calendar. The syntax is as follows:
    <?xdoxslt:date_diff(‘format’, ‘YYYY-MM-DD’, ‘YYYY-MM-DD’, $_XDOLOCALE, $_XDOTIMEZONE)?>
    where
    format is the time value for which the difference is to be calculated
    Example:
    <?xdoxslt:date_diff(‘d’, ‘2006-04-08’, ‘2006-04-01’, $_XDOLOCALE, ‘America/Los_Angeles’)?>
    returns
    -7

  • Credit block for Slaes Order on Days Basis

    Hi SAP Gurus,
    As my client requirement want Credit block for sales order with days basis.For  example Customer has  credit 5000 and  30 days.Even credit value not exceed on 31st day, But sales order has  to block .
    Please requesting to all kindly needful for me.

    Hi
    Check payment terms in Customer master data, billing tab page. We can define payment terms. And if you want to block the customer use dynamic credit check.
    Enter 5,000/- in maximum document value in FD32
    For Credit management to be working
    1. In def of SD type we need to speciy Automatic credit control in the field " Check Credit Limit"
    2. In the defination of corresponding item category we have to check the field "Credit Active".
    Award points if it is useful
    Anil

  • Add number of days to a date

    Hi, all
    somebody know if i can add days to a date with a dynamic action??
    Thank for your help

    Hi Francisco,
    You can use a external subroutine to do so.
    In the dynamic action:
    for that infotype you can specify an entry with Step type F and Variable function part with the routine name(The new calculated date is returned in the RP50D-DATE1 field)
    EXAMPLE:
    STEP1 :In dynamic action create these 2 entries
    0000|     |    | 06 | 457 |  F  | GET_DATE(ZHPADYN).
    0000|     |    | 06 | 456 |  W | P0041-DAT01=RP50D-DATE1
    STEP2: Then create Subroutine pool in SE38 ( Program type S)
    PROGRAM  ZHPADYN.
    TABLES : RP50D,
             P0000.
    *&      Form  GET_DATE
    FORM GET_DATE .
      RP50D-DATE1 = P0000-BEGDA - 1.
    ENDFORM.                    "GET_DATE
    Hope this helps.
    Thanks,
    Puneet

  • How to add one day to a Date?

    Hi,
    What is the simplest way to daa one day to a Date object?
    Thanks.
    Pengyou

    You use a database query just to add one day
    to a Date object? I wouldn't call that the "simplest"
    way at all.I was going to suggest firing off an email to the naval observatory and having them carry out the calculation, emailing the result back (maybe using JMS, not sure - web service possibly?) but the OP's way is simpler.

  • Source inspection before 365 days of delivery date of purchase order

    Hi Experts,
    Business wants to create source inspection lot well in advance before 365 days of delivery date of purchase order. this lot is required to record results.
    In SAP, transaction code QA51 allows only two digit characters for 'number of days for opening period' so system is not creating inspection lot for more than 99 days delivery date from current date.
    Please advise.

    Hi Patel, I really got interested on this particular issue because we have been using source inspection in our company for a while. After some investigation on ABAP code of report I will share with you my fact findings:
    1) System calculates the start date of source inspection (delivery date from PO - Leadtime from q-info record). For example, in my test case it was 14.08.2015 - 0 days. So field g_datum below will be 14.08.2015:
    2) System then checks if you are running the report in background (highlighted in yellow above). If so then it will check if the start date of inspection (g_datum) falls on opening horizon (g_datum_eroff). The opening horizon is calculated as per formula below (system login date + opening period). As an example: 14.08.2014 + 30 days = 13.09.2014.
    Default opening period (p_eroff) is 30 days:
    3) So all-in-all, when you are running QI07 online you´ll get a yellow traffic light on the long leadtime PO but you will be able to process it (on-line). However if you run the report in background (job scheduling) system will only create inspection lot to the relevant POs if the PO's delivery date falls on the 30 days window based upon the current date.

  • GRN date as deafult Base Line Date in MIRO

    Dear All,
    The client requirement is like this,
    The default Base Line date for MIRO Document should be the GRN Date (MIGO Date). But in Payment Term configuration only Document Date, Posting Date, No default, Entry Date are there. We can change the base line date at the time of MIRO.
    But Client requirement is it should come by default at the time of doing MIRO,
    Is there any user exit or enhancement for this.
    Sree

    Hi,
    We have come across this requirement in some implementations and the workaround is done this way:
    During Inovice Verification leave the system to determine Base Line Date based on standard settings.
    You can anyhow change the baseline date in document change mode.
    Have a Development which can identify the docuements posted during a period say every day and get the base line date changed on your logic (you would able to get the full trace with GR).
    Have this program executed every day on background.
    Your logic should also take care of invoice verifications with multiple GRs made at different time for the same invoice (usually the last GR date is taken in this circumstance).
    Hope this helps you.
    Varadharajan

  • Add days to a date - BI Publisher

    Hello,
    I am trying to add 7 days to a date. The date starts as DD-MM-YY format, but I need it to display as DD.MM.YYYY.
    I can get the following to return the date in the correct format:
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2)),'DD.MM.YYYY')?>
    But I am unable to add 7 days to this date. I have tried using +7 in various places in the tag but no luck. Here are some things I've tried:
    Within the "to_char" function causes error "oracle.xdo.parser.v2.XPathException: Cannot convert 2010-11-30 to number"
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2)+7),'DD.MM.YYYY')?>
    Within the "to_date" function causes the same error "oracle.xdo.parser.v2.XPathException: Cannot convert 2010-11-30 to number."
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2))+7,'DD.MM.YYYY')?>
    Outside all functions itstill errors, but with a slightly different error: "Cannot convert 30.11.2010 to number"
    <?xdofx: to_date(to_char('20'||substr(DUN_DATE,7,2)||'-'||substr(DUN_DATE,4,2)||'-'||substr(DUN_DATE,1,2)),'DD.MM.YYYY')+7?>
    Any ideas how to get the calculation to work correctly?
    Thanks in advance,
    JJ

    Found a soution, it's not very clean and there are probably better ways, but it works.. if anyone has alternatives I'd be intereseted.
    1.) Set a variable XDUN that converts the date from DD-MM-YY to the the BI-supported date format YYYY-MM-DD using substring and concat functions:
    <?xdoxslt:set_variable($_XDOCTX, ’XDUN’, concat('20',substring(/ARDLP/LIST_G_CORRESPONDENCES/G_CORRESPONDENCES/DUN_DATE,7,2),'-',substring(/ARDLP/LIST_G_CORRESPONDENCES/G_CORRESPONDENCES/DUN_DATE,4,2),'-',substring(/ARDLP/LIST_G_CORRESPONDENCES/G_CORRESPONDENCES/DUN_DATE,1,2)))?>
    2.) Set another variable XDUN7 based on the first variable, and add 7 days there. Also formats the date in DD.MM.YYYY format:
    <?xdoxslt:set_variable($_XDOCTX, ’XDUN7’,xdoxslt:ora_format_date(xdoxslt:ora_format_date_offset(xdoxslt:ora_format_date(xdoxslt:get_variable($_XDOCTX,’XDUN'), 'YYYY-MM-DD'),7,'+'),'DD.MM.YYYY'))?>
    3.) Call the variable to display the date + 7
    <?xdoxslt:get_variable($_XDOCTX, ’XDUN7')?>
    Thanks,
    JJ

  • Adobe LiveCycle Designer 8 - Add days to Current Date in another text field

    Hi-
    I am working on an expense report. I have six fields, CurrentDate, and countDate1 through countDate5. The CurrentDate is a Time/Date field which the user can select whatever date is needed with the drop down calendar. The other five countDate fields are "text" fields which will represent Monday through Friday. I would like to add zero days to whatever the user selects as the CurrentDate and make that appear in countDate1 which represents Monday(the CurrentDate the user selects will always be a Monday), add one day to whatever the user selects as the CurrentDate and make that appear in countDate2 which represents Tuesday...and so on. I realize this is probably basic for someone familiar with FormCalc but I'm very new at this.
    This got me very close but I want the user to select the date and not have the CurrentDate already filled in.
    CurrentDate - DateTime field, FormCalc calculation script:
    num2date(Date())
    Date1 - Text field, FormCalc calculation script:
    Num2Date( Date2Num(CurrentDate.formattedValue))
    Date2 - Text field, FormCalc calculation script:
    Num2Date( Date2Num(CurrentDate.formattedValue) + 1 )
    Thanks!
    Brian

    Here is an exmaple of adding days the script is used in the "exit" event for the date select field that has display format of "MM/DD/YYYY". Adding days requires add x number of days to the days since the epoch date for the current date, adding months or years one needs to manipulate the string parts of the date.
    ----- form1.#subform[0].InputDateField::exit: - (FormCalc, client) ---------------------------------
    // fomatted string for selected date
    var sFmtDateValue = $.formattedValue
    var sMsg = Concat("Entered date formatted: ", sFmtDateValue) // build message string
    sMsg = Concat(sMsg, "\u000a" ) // add new line to message
    // convert date string to days since epoch date - format is important
    var fDaysPast = Date2Num(sFmtDateValue, "MM/DD/YYYY")
    // add 7 days to days past epoch date
    var f7DaysPlus = fDaysPast + 7 // add 7 days
    var s7DaysPlus = Num2Date(f7DaysPlus, "MMM DD, YYYY") // format string for 7 days plus
    sMsg = Concat(sMsg, "\u000a", "Plus 7 Days: ", s7DaysPlus) // build message string
    // add 14 days to days past epoch date
    var f14DaysPlus = fDaysPast + 14 // add 7 days
    var s14DaysPlus = Num2Date(f14DaysPlus, "MMMM DD, YYYY") // format string for 7 days plus
    sMsg = Concat(sMsg, "\u000a", "Plus 14 Days: ", s14DaysPlus) // build message string
    // display results
    // work on months
    // get parts of date past epoch date
    var sFullYear = Num2Date(fDaysPast, "YYYY") // get 4 digit year form days past epoch date
    var sMonth = Num2Date(fDaysPast, "MM") // get month form days past epoch date as number
    var sDate = Num2Date(fDaysPast, "DD") // get date form days past epoch date as a number
    var s2Month = Sum(sMonth, 2) // add 2 months
    var s2FullYear = sFullYear
    // if more than 12 months in new date adjust year on number of months
    if (s2Month > "12") then
    s2FullYear = Sum(s2FullYear, + 1) // increment year
    s2Month = Sum(s2Month, - 12) // adjsut months
    endif
    var s2MonthsAdded = Concat(s2Month, "/", sDate, "/", s2FullYear) // date string
    sMsg = Concat(sMsg, "\u000a", "Added 2 months: ", s2MonthsAdded) // display stringxfa.host.messageBox(sMsg, "Sample Adding Days" ,3, 0);
    var s5Month = Sum(sMonth, 5) // add 5 months
    var s5FullYear = sFullYear
    // if more than 12 months in new date adjust year on number of months
    if (s5Month > "12") then
    s5FullYear = Sum(s5FullYear, + 1) // increment year
    s5Month = Sum(s5Month, - 12) // adjsut months
    endif
    var s5MonthsAdded = Concat(s5Month, "/", sDate, "/", s5FullYear) //build Date string
    sMsg = Concat(sMsg, "\u000a", "Added 5 months: ", s5MonthsAdded) // display stringxfa.host.messageBox(sMsg, "Sample Adding Days" ,3, 0);
    // display results
    xfa.host.messageBox(sMsg, "Sample Adding Days and Months" ,3, 0);

Maybe you are looking for