Substract days to a date

Does somebody know a method to substract to a given date (in String format dd/mm/yyyy) a given number of days??
public String restarDias(String fecha, int dias) throws Exception {
DateFormat df = DateFormat.getDateInstance();
Date fechaD = df.parse(fecha);
return dateResult;
}.. thanks!

Hi,
you can do this easily when you define a Calendar and then apply the method:
//somewhere in code
//Calendar Cal = Calendar.getInstance();
Cal.add(Calendar.DATE,3); //to add 3 days
Cal.add(Calendar.DATE,-1);//to substract one day
greetings,
alina3

Similar Messages

  • Working days between two date fields and Changing Factory Calendar

    Hi,
    I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
    I have written the routine using factory calender and its working fine except for two problems now:
    1. If any one of the date field is empty then teh rsult should be zero.
    2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
    I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
    I am new to ABAP. Please help me how i can achieve these for below code.
    DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
          IS_HOLIDAYS TYPE ISCAL_DAY.
    DATA: T_DATE TYPE SY-DATUM,
          P_DATE TYPE SY-DATUM.
    DATA : X_DATE(4) TYPE C.
    DATA: CNT TYPE I.
    REFRESH : IT_HOLIDAYS.
    CLEAR : IT_HOLIDAYS.
    T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
    P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
    CALL FUNCTION 'HOLIDAY_GET'
    EXPORTING
    HOLIDAY_CALENDAR = 'CH'
    FACTORY_CALENDAR = 'CH'
    DATE_FROM = P_DATE
    DATE_TO   = T_DATE
    TABLES
    HOLIDAYS = IT_HOLIDAYS
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    DATE_HAS_INVALID_FORMAT = 3
    DATE_INCONSISTENCY = 4
    OTHERS = 5.
    DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
    X_DATE = T_DATE - P_DATE - CNT.
    RESULT = X_DATE.
    Please help
    Regards
    Zabina
    Edited by: Syed786 on Nov 2, 2011 9:15 AM

    Hi Zabina,
    Try this function module  'DURATION_DETERMINE'.
    Give the factory calendar and unit as DAY
    With regards,
    Rajesh

  • 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

  • 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 Days into a Date from java.util.Date class

    I have a problem when i wants to add 2 or days into a
    date object geting by java.util.Date class. so please help me resolve this issue?
    for e.g i have a date object having 30/06/2001,
    by adding 2 days i want 02/07/2001 date object ?
    Code
    public class test2
    public static void main(String args[])
    java.util.Date postDate = new java.util.Date();
    myNewDate = postDate /* ?*/;
    Here i want to add 2 date into postDate

    Use Calendar...
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.DAY, 2); // I'm not sure about that "DAY"

  • Next upcoming expert day Looking forward to the next Expert Day any estimated date of the event

    next upcoming expert day Looking forward to the next Expert Day any estimated date of the event
    it‘s great to be able to post in the forum and obtain help
    my gratitude and appreciation is certainly provided; may I inquire
    as to any estimate Is there another
    Upcoming Expert Day Event
    Since the designated Expert Day is stated as the event has now concluded for
    Expert Day in English (Consumer) - April 18-19, 2012
    Hopefully before September
    Thanks  
    Respectfully

    However if it is Sep I’ll gladly wait and that is still excellent the designated Expert Day’s are great
    my gratitude and appreciation is certainly provided..

  • What is the best way to add a day to a Date object?

    I have come across numerous examples on adding a day to the CURRENT date, using the Calendar object. However, what I need to do is to add a day to a Date variable.
    Can someone tell me how to do that? I tried to set the value of my Date variable into the Calendar object, but, it appears that for the current JAVA version, they have deprecated the getYear(), getMonth() and getDay() methods for the Date class.
    Really appreciate your suggestions.
    Thank you in advance,
    SiowLing

    I haven't seen the OP express a concern over how to create/obtain the Date object (he could be using "new Date()" given the emphasis on "CURRENT"). Milliseconds is fine too if that's what you have (for example from a java.sql.Date).
    So the way to add a day to a Date object (the OPs original question) is to:
    - set the Date on a Calendar using setTime
    - add 1 to the DATE field of the calendar
    - get the Date from the Calendar using getTime
    Obviously you're right if the OP doesn't have Date object to start with, but just the "numbers" for year, month, day.

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

  • Adding 1 day to a date in BPEL

    Hi,
    Im trying to add 1 day to a date in a BPEL proces. I saw that there was a xp20:add-dayTimeDuration-to-dateTime so I tried using this in several ways. I didnt expect the input variable to be a string. I tried converting my date to a string and adding 1 day like this:
    xp20:add-dayTimeDuration-to-dateTime(xp20:format-dateTime(string(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum')), 'YYYY-MM-DD'), 'P1D')
    But the variables which I try to fill stays empty. The element which I try to fill is of type dateTime. Is this maybe the error that add-dayTimeDuration-to-dateTime returns a string and it cannot cast it to dateTime?
    Can anyone tell me how to solve this properly?
    Thanks in advance!

    Hi,
    I refactored my expression to look like this:
    xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum'), 'P1D'), '[Y]-[M]-[D]')
    But the I receive an error: XMLElement cannot be cast to java.lang.String
    Then I tried:
    xp20:format-dateTime(string(xp20:add-dayTimeDuration-to-dateTime(bpws:getVariableData('inputVariable','payload','/ns1:GereedMeldenRoosterRequest/StartDatum')), 'P1D'), '[Y]-[M]-[D]')
    Because xp20:add-dayTimeDuration-to-dateTime needs a String as input and I dont know how getVariableData returned it but with this I get the error:Parse Error in string function
    Any ideas?

  • Report Builder Error: [BC30455] Argument not specified for parameter 'DateValue' of 'Public Function Day(DateValue As Date) As Integer'.

    Hi there!
    I'm trying to calculate the difference between two days using DATEDIFF (). I use following code for this:
    =DATEDIFF(DAY, CDate(Fields!Eingang_Kundenanfrage.Value),CDate(Fields!Ausgang_Angebot.Value))
    Every time I try to save the report, I get this error message:
    [BC30455] Argument not specified for parameter 'DateValue' of 'Public Function Day(DateValue As Date) As Integer'.
    The DataSource is a SharePoint List and the Date is given in the following format: 23.05.2014 00:00:00 (DD.MM.YYYY HH:MM:SS).
    I've googled for a working solution for a long time now, but I had no success.
    Is there someone who can help me?

    Hi Lucas,
    According to your description, you want to return the difference between two date. It seems that you want to get the days. Right?
    In Reporting Services, when we use DATEDIFF() function, we need to specify the data interval type, for days we can use "dd" or DateInterval.Day. So the expression should be like:
    =DATEDIFF(DateInterval.Day, CDate(Fields!Eingang_Kundenanfrage.Value),CDate(Fields!Ausgang_Angebot.Value))
    OR
    =DATEDIFF("dd", CDate(Fields!Eingang_Kundenanfrage.Value),CDate(Fields!Ausgang_Angebot.Value))
    Reference:
    Expression Examples (Report Builder and SSRS)
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Extract data on report between last 30 days from current date.

    Hi Experts,
    Ealrier i had provided user promt to select the date range, now i need to schedule the report for this i have to set the date between last 30 days from current date.
    How can i add this in formaula on record selection.
    before:
    {pm_process.pm_creation_date} in {@Start Date to UTC} to {@End Date to UTC}
    I tried:
    {pm_process.pm_creation_date} in CurrentDate() - 30 to CurrentDate()
    But this is diplaying me only data of 30th date from current date.
    Please advice.

    Hi Brian,
    Thank you!
    1. I have not created any function for {pm_process.pm_creation_date} in [CurrentDate() - 30 to CurrentDate()] i am just adding this on Record Selection and its not helping.
    2. {pm_process.pm_creation_date} in Last30Days; this is throwing below error.
    please advice what to be done?

  • Lockbox Issue with payment on exact day as Cash Discount Days 1 Due Date

    Dear Gurus
    We are running into an issue in as much as when we receive a payment against our Lockbox on the exact day as the Cash Discount Days 1 due date the system posts this as an on account posting as opposed to applying the cash against the open receivable and posting the difference to the Cash Discount Account.
    E.g. Invoice 10000 Payment term 34 days 2% Net 35. I created the AR invoice today with invoice date and posting date of Oct 9, 2009 and posted the same. Received payment $ 9800 on Lockbox file today Nov 12 using the BAI2 format Lockbox file and found that the system did not even show the invoice # on the Lockbox reports but it recognized the customer based on the MICR # and posted an on account payment. It gave the error" F5 263 Difference too large for Clearing"
    The users have prior complained that this situation arises in F-28 as well where they would have to force the discount instead of the system recognizing the same if cash was being applied on the same date as the Cash discount Days 1 due date.
    Any help in this regards will be geratly appreciated and points awarded.
    Regards
    Satpal Narang

    Hi Satpal,
    Please check the net due date of the document which you are trying to do the payment. As it is critical information to calculate the cash discount.
    I hope this helps.
    Regards
    Ravinagh Boni

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

  • Adding days to a date

    Hi, i've been trying to add days to a date with no luck.
    I have two dates.
    Date date1= new Date();
    Date date2;
    I want date2 to equal x amount of days from date1.
    eg. date1 = 6/10/2004
    I want date2 to be 4 days from date1 so date2 would be 10/10/2004. i know this is very easy to do with the Calendar class but in my program it needs to be a Date because i parse Strings (dd/mm/yyyy) to Dates. It is not possible to parse Strings to Calendar date's right?
    So if anyone can help me add days to a Date object, it would be great!
    Thanks

    >
    testParse.java:33: 'void' type not allowed here
    System.out.println (testDate2.setTime(newTime));You are trying to print out the results of the void
    method, i.e. a void, not the object.
    d-unknown, if you look closely at the error message provided and the line it's complaining about, and use a little process of elimination, I think you'll find that there are only so many possibilities as to what possibly could be wrong.
    These compiler errors are not cryptic curses thrown up to stop people from getting work done, the counterspells to which are only known to those who have been through the rite of passage and had a coffee cup branded on their butts. The error messages are your friends. They tell you pretty precisely what went wrong and where if you take the time and effort to read an understand them.
    "'void' type not allowed here" -- Where have you ever seen the word void when programming Java? As the return type of a method, right? So, "'void' type" is probaby talking about the return type of some method.
    "not allowed here" -- well, it looks like you're doing something with a void where you can't have a void.
    There are only two method calls on that line--println and setTime. Both return void, so either one could be the problem. Either one might be being used where it's not allowed.
    But wait, what could possibly be wrong with where you're using println? It's just like every other println you've ever used.
    What about setTime? Well, println has several signatures. One takes object, and there's one for int, float, etc. So what you pass to println has to be one of those types. Is the return type of setTime an Object or int or long or anything? No, it's void. It's nothing. It has no value. println needs a value, but you're passing something that has no value. It would be like saying x=date2.setTime(...) It makes no sense, because a method with a void return type doesn't return any value.
    See, that wasn't so hard, was it? Yeah, it was wordy, but really if you start with "what could be void in this line and how could it be causing a problem," the thought process only has a few steps to get to the answer.

  • Adding hours/day to a date

    Hello,
    I have field of length 20 which contains date in the format “mm/dd/yyyy hh:mm:ss”.
    I want to add 5 hrs, 8 hrs, 2 days to this date value depending upon some condition.
    Can anyone please suggest how to do this or any FM which does this.
    Thanks in advance

    Hi..
    DATA : FA(20) TYPE c,
           FB(10) TYPE c,
           FC     TYPE d,
           FD(8)  TYPE c,
           FE     TYPE t.
    data : f_m(10) type c,
           f_d(10) type c,
           f_y(10) type c,
           f_h(10) type c,
           f_mi(10) type c,
           f_s(10)  type c,
           f_aa(10) type c,
           f_bb(10) type c.
    FA = '07/01/2007 08:09:10'.
    SPLIT fa AT space INTO f_aa f_bb.
    SPLIT f_aa AT '/' INTO f_m f_d f_y.
    SPLIT f_bb AT ':' INTO f_h f_mi f_s.
    add your logic...
    i want to help you.
    regards..

Maybe you are looking for

  • Is there any way of extending a polynomial trendline in Numbers '09?

    Hi, The question title says it all really.  Is there any way of extending a polynomial trendline in Numbers '09, beyond the data that I currently have?  I can do this in Excel, but would like to be able to do this in Numbers too. Thanks, Nick

  • Why does Server Monitor not work with non-Xserves?

    Does anyone know why Server Monitor does not work with non-Xserve computers? We acquired a Power Mac for a server, based on there being no apparent difference except for the obvious. Turns out there are some differences after all. Do Power Macs lack

  • Width / Height pixel information on images in finder no longer there?

    I rely heavily on this feature for my job, and it seems to have stopped working! When finder is in the 'multi-column' mode, when clicking on an image, amongst the information shown to the right of it (including name, kind, size etc) used to be the pi

  • Annotating a Web Document?

    As is often the case, we have a great idea, but can’t seem to figure out to make it work. Any help in this matter would be greatly appreciated. Some background: we have a web application that is used primarily by university-level student writers, the

  • How to mount ovm3.x guest disk to ovms

    Hi, we face a problem regarding a system.img from an ovms(ol5.9) So I will check parts of the fs and need to mount the system.img(ovms guest disk image) to the local file system. In ovm2.x I need to to use lomount but in ovm3.x there is no command li