UDF for Date -7 days

Hi everyone
I am fairly new to Java and PI, and I have to create a UDF that takes the currentDate and subtracts 7 days. I was just wondering the best way to go about this with java?
Thank You

UDF Code as below ..
Calendar now = Calendar.getInstance();
now.add(Calendar.DATE, -7);
String subtractSevenDays = new SimpleDateFormat("yyyy/MM/dd").format(now.getTime());
return subtractSevenDays;
// Dont forget below import statements
import java.text.SimpleDateFormat;
import java.util.Calendar;
Map it to target field. 
Note: You can choose any pattern in the above SimpleDateFormat argument.
Currently the output will be ex:    2011/04/01
Edited by: Baskar Gopal on Apr 8, 2011 10:56 AM

Similar Messages

  • UDF for Date format

    Hi,
    I want to write an UDF
    I want to pass Date as an String in format yyyymmdd.
    I want to convert it to mm/dd/yyyy. & pass new date as o/p/
    But there is a possibility that i/p Date may come as blank in that case I want to keep output as blank.
    Please help

    Thanks guys,
    I am using this code but get an error
    int len;
    len = Date.length();
    if (len>7)
    String year = Date.substring (0,4);
    String month = Date.substring (4,2);
    String day = Date.substring (6,2);
    String f  = month + "/" + day + "/" + year;
    return f;
    else
    return Date;
    --- Here when I run this in test mode I get this exception -
    Exception:[java.lang.StringIndexOutOfBoundsException: String index out of range: -2] in class com.sap.xi.tf._MM_PSN_EMP_INFO_ method check$[19880517, B1, A1, C1, F1, G1, H1, X1, X1, X1, X1, X1, X1, 07, 5, com.sap.aii.mappingtool.tf3.rt.Context@7ab97403]
    Please help.

  • How to get the date for the last day of a week?

    Is there a easy way to get the date for the last day of week?
    eg a week starts on monday and end on sunday
    January 11, 2005 is the start date for the week
    January 17, 2005 is the end date for the week
    or
    say
    February 26, 2003 is the start date for the week
    March 5, 2003 is the end date for the week
    I just need a simple way of figuring that out....
    I figured out how to get the start date for the week but just can't get the latter..
    formatting of the date is not of a concern.. that I know how to do
    thanks in advance

    How about something like the following?
         Calendar someDay = new GregorianCalendar(2005,0,11);//2005 Jan, 11
         //Note above that January is 0, not 1, as counting starts from 0.
          someDay.add(Calendar.DAY_OF_MONTH,6); //add 6 days
         java.util.Date  lastDayOfWeek = someDay.getTime();
         //If someDay was the start of a week, lastDayOfWeek should now be
         //the last day of that week.
         System.out.println(lastDayOfWeek.toString() );

  • How to identify the maximum data loads done for a particular day?

    Hi all,
    There is huge volume of data been loaded on a last monday, and then data was deleted from the cubes on the same day. And hence i needs to see which are all the cubes which was loaded wtih lot of records for a particular day,
    i happened to look at rsmo, i am unable to see the ods nor the cube data loads,
    were do i seet it?
    Thanks

    See if the table RSSELDONE helps. This will give you the recent data load details. Based on those loads , you can search the targets.
    And also check table TBTCO  which will give the latest job details. You will have to analyze the same jobs to know what loads were done . Give a selection for date.

  • Function Module for selecting date by day

    Is there any function module to choose date by day. for example if I give today's date the FM should give me next thursday's date.
    Thanks
    Tharani

    this works good........
    *& Report  YCHATEST                                                    *
    REPORT  YCHATEST
    data:day like DTRESR-WEEKDAY.
    parameters:curr_dat like sy-datum default sy-datum.
    CALL FUNCTION 'DATE_TO_DAY'
      EXPORTING
        DATE          = CURR_DAT
    IMPORTING
       WEEKDAY       = day.
    write : / day.
    case day.
    when 'Monday'.
       CURR_DAT = CURR_DAT + 3.
    when 'Tuesday'.
       CURR_DAT = CURR_DAT + 2.
    when 'Wed.'.
       CURR_DAT = CURR_DAT + 1.
    when 'Thursday'.
       CURR_DAT = CURR_DAT + 7.
    when 'Friday'.
       CURR_DAT = CURR_DAT + 6.
    when 'Sat.'.
       CURR_DAT = CURR_DAT + 5.
    when 'Sunday'.
       CURR_DAT = CURR_DAT + 4.
    endcase.
      write :/ CURR_DAT.

  • ABAP Classes for date & day computation

    <<Date questions have been asked so many times that they are not permitted in the ABAP forums>>
    Hello, I have a requirement to get the date of last 2 thursdays. Can somebody please help with the class I should use for the purpose?
    Thanks!
    Edited by: Matt on Aug 16, 2011 11:50 AM

    Hey,
    DATE_COMPUTE_DAY will give you DAY number for any date, with day number 1 as Monday .....4 as Thursday....and 7 as Sunday.
    SO, you can use ..
    data: lv_day type SCAL-INDICATOR,
          lv_diff type i,
          lv_thurs1 type sy-datum,
          lv_thurs2 type sy-datum.
    PARAMETERS: p_date type datum DEFAULT sy-datum.
    CALL FUNCTION 'DATE_COMPUTE_DAY'
      EXPORTING
        date          = p_date
      IMPORTING
        DAY           = lv_day
    lv_diff = lv_day - 4.         "since Thursday is 4
    if lv_diff GT 0.
      lv_thurs1 = p_date - lv_diff.
    else.
      lv_thurs1 = p_date - 7 - lv_diff.
    endif.
      lv_thurs2 = lv_thurs1 - 7.
      write:/ lv_thurs1, lv_thurs2.
    I have not included today's date if it is Thursday, if you want to include it, change 'GT' to 'GE'.
    BR,
    Diwakar
    Edited by: Diwakar Aggarwal on Aug 16, 2011 10:49 AM

  • Calling webservice in udf for inserting data into webservice

    Dear Experts,
          Please give me the drawbacks of using lookup function for inserting data. we are calling a webservice from the udf for inserting the data using a webservice.
    It is a file to jdbc usnig a soap lookup . we use this approach because we need to pass the response from webservice along with the error data to the jdbc.   is there any other way to do it without using bpm ?
        In the udf we are creating the xml structure for webservice and passing the parameters through arguments.
    is there a better approach for this ?
    Thanks,
    Aju

    Hi Aju,
    You can do it without BPM.
    Write UDF for Soap Lookup. Parse the response message from Webservice.  and map the required values to respective fields.
    See the weblog
    Webservice Calls From a User Defined Function.
    Negative point of this solution is that it will take some time to call Webservice and get response back from it.
    Kulwinder

  • UDF for Item Master Data

    Hi,
    The UDF options in the menu bar for the Item Master Data are available in one database but NOT in another database.
    Is this a known bug and/or related to conversion of a database from a previous version.
    We're using SBO 6.5 SP:01 EF:07
    Thanks

    Hi,
    UDF options in the menu bar are only visible if there are defined UDF for the active form. Are you sure that the seccond database has any UDF?
    Regards,
    Ibai Peñ

  • UDF for sorting date

    Hi Guys,
    I am doing scenario File to Idoc, i have to sort date in acending order, the date format will be in either 22.10.2007 or 22/10/2007 . can any one send UDF for this.
    Regards,
    venu gopal

    Hi Venu
    You can execute this without UDF. Use " Transform" function in the Date functions.
    When you are using the UDF....you keep the strucure as "yyyMMddhhmmss" for that clickon Trnasform function and there you can see ShowAdvancedProperties...there u can find the format of the source which you are expecting and also change the strucutre of you target expected format.
    You please try this and check the mapping it will get execute.
    Use Standard Date Function DATATRANS. It have the property for format and input is the source date field. It will convert the date format to required specified format which you menstion in the DARTATRANS function
    for UDF
    Re: UDF  for this mapping rule
    Re: Problem in UDF please Help?
    Thanks!

  • Formula for dates back 7 days failing because of end of month?

    HI I have a CR that has been working fine till now. it runs every Sunday late in the day and looks back past 7 days. it has formula for dates from and to.
    tonumber(totext(CurrentDate,'yyyyMMdd'))-6
    and tonumber(totext(CurrentDate,'yyyyMMdd'))
    yet this past Sunday, it is not giving all previous 7 days. could it be related in any to the end of month? i cant think this is it. but perhaps.the date col is type = NUMBER and in YYYYMMDD.
    WHen I ran this report manually by selecting on the dates needed it returns more data.

    Hi Paul,
    The issue is when you convert a date to number a subtract 6 from it, it doesn't go 6 days back; it just subtracts 6 days from that converted number.
    So, today, represented as a number would be 20140804 however, when you subtract 6 from this number you get : 20140798 which of couse is Not a date.
    Your code (if the dates are stored as number in the database) should be :
    tonumber(totext(CurrentDate-6,'yyyyMMdd'))
    -Abhilash

  • Scripts for OTN Developer Day - Big Data

    Hi,
    I was wondering if anybody knows where to find the scripts used for "OTN Developer Day - Big Data" which was held during February/March 2014?
    The "Lab Guide" can be found in: https://www.oracle.com/webfolder/s/delivery_production/docs/FY14h1/BigDataWorkshop.pdf
    Regards,
    Babak.

    Not sure if these are the exact same ones, but it should be very close: Oracle Big Data Lite Virtual Machine
    It will also get you to the page where the VM is frequently updated and the HOL sections come with the updated VM.
    JP

  • BB off for a few days -- When turn on reconciled emails all show one date/time.

    If I am away for a few days -- with the Blackberry off -- Then when I return and turn on the unit, it will reconcile email through my work blackberry server.  The emails that get downloaded at that time all show on my blackberry email listing as received at one time -- when the reconciliation occurred -- not the dates/times that the actual emails were written.  My work email (on my computer at work) will show the dates/times that the actual emails were written -- even though I also had been logged out from my work email for the time I was away.  This is a real pain for viewing / looking through and finding emails later on the device.  So now, I have to leave the unit on and plugged into the wall when away -- so my emails will show the right date/time on the device.  Is there a way to set things up so I don't have to resort to this? -- seems to me that there must be -- otherwise a lot more people would raise this concern.
    Thanks,

    The last time I checked the incoming emails will always go by the date/time on the device itself. There is not a way to change this behavior.
    Do you turn it off to conserve battery power? If so you can always place the device in Standby mode. The battery drains much slower in this mode and should last anywhere from 10-15 days.
    If someone has been helpful please consider giving them kudos by clicking the star to the left of their post.
    Remember to resolve your thread by clicking Accepted Solution.

  • Hi transferring data from old to new and it is stuck on 1 min remaining for 1.5 days now.  any ideas

    transferring data from old to new and stuck on one min remaining for 1.5 days.  any ideas

    If you have already tried restarting the process and it continues to stall out, the only way to do it is through target disk mode. Because USB C is so new there is not an official way to do it. If you take it into an Apple Store they should transfer your data for free.

  • Function module for calculating next day's date

    Dear all,
    We have a requirement of displaying transaction validity date on SAP smart form. The date input is available from the transaction.
    We need to add 1 day to this to get correct date printed in the output. We applied the logic of 'input date +1', but this logic does not give correct output when the final date co-incides with change in month (i.e 1st of next month).
    Is there any function module available which would do the addition in proper date format and calculate next day's date correctly?
    Regards,
    DS

    Use FM RP_CALC_DATE_IN_INTERVAL
    Example :
    data: v_curr type sy-datum,
    v_next type sy-datum.
    v_curr = '20080415'.
    CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
    EXPORTING
    DATE = v_curr
    DAYS = '01'
    MONTHS = '0'
    SIGNUM = '+'
    YEARS = 0
    IMPORTING
    CALC_DATE = v_next.
    write:/5 'Current date', v_curr.
    write:/5 'Future date', v_next.

  • Material opening and closing stock for a given day- Tables or FM

    Dear Friends
             i have to make a report  , related to Material opening and closing stock for a given day  , i check the T-Code- MB5B ,
    it is not giving correct date . is any functional module is available  ? . i checked some table like mbew , mard . it is also not giving correct requirement . Please help

    Hi
    Goto transaction MC.9, Give your Material and,Plant and the date which you need to know the closing stock. Do make sure that in the high and low values you are giving the same date there. I guess no such FM are available for this. You can refer the  [Link|https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=15856]  for some help.
    Regards
    Vinodh
    Edited by: Vinodh_AN on Dec 15, 2010 9:19 AM
    Edited by: Vinodh_AN on Dec 15, 2010 9:25 AM

Maybe you are looking for