Calculate date for a week ago

Part of an assignment I have is to delete logs that are a week or more older. How can I calculate the day to be 7 days ago from the current? Ive been looking at the Calendar's static properties, but I'm not if subtracting 7 from them would work.
Thanks

Cant say ive actually tried it while running the program, more or less been reading through the docs.
public void checkForOldLogs() {
     Calendar rightNow = Calendar.getInstance();
     int weekago = rightNow.get(Calendar.DATE - 7);
}Is what I was thinking, but im not sure if itll roll over month wise or not.
EDIT: That doesnt work, as I did a println for the weekago, get an out of bounds exception.
My log files are in the format of useridyyyymmdd.LOG
the userid is ALWAYS 8 characters long, so I could do a search for files with the userid that have an older date of that format than the current one by a week.
Code for generating the String for the filename:
public void setCurrentDate() {
     Calendar rightNow = Calendar.getInstance();
     String year = Integer.toString(rightNow.get(Calendar.YEAR));
     String month = Integer.toString(rightNow.get(Calendar.MONTH) + 1);
     String day = Integer.toString(rightNow.get(Calendar.DAY_OF_MONTH));
     if(month.length() == 1) {
          month = "0" + month;
     if(day.length() == 1) {
          day = "0" + day;
     dateString = year + month + day;
}Edited by: agm_ultimatex on Jul 1, 2009 7:09 PM

Similar Messages

  • Calculate Dates for Last week and next three weeks

    Hi,
    I have a report where I need to calculate dates between last week and the next three weeks (not counting current week). I'm familar with the first part, it could be done by using the LastFullweek function but not sure how I can avoid the current week and calculate the next three weeks.
    Any help is greatly appreciated.
    Thanks!

    ... and here are a few more...
    Last Week...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate), #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -1, #1/7/1900#)
    THEN TRUE ELSE FALSE
    The week before...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -1, #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -2, #1/7/1900#)
    THEN TRUE ELSE FALSE
    And the week before that...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -2, #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -3, #1/7/1900#)
    THEN TRUE ELSE FALSE
    and of course all 3 weeks together...
    IF {TableName.Date} IN
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate), #1/7/1900#)
    To
    DateAdd("ww", DateDiff("ww", #1/7/1900#, CurrentDate) -3, #1/7/1900#)
    THEN TRUE ELSE FALSE
    If you want the 1st day of the week to be Monday instead of Sunday just change the date of #1/7/190# to #1/1/1900#
    HTH,
    Jason

  • How to get data for current week and previous week using customer exit in Bex.

    Hi everyone,
    I have a scenario in which I need to display data for current week and previous week (based on "sy_datum" the program has to calculate current week and previous week) in Bex using  Customer exit. I have created one variable in Bex Query Designer and I have written code for the variable in CMOD. But it is not working fine, (I know that we can do the same by using offset value in Bex). Can some one guide me how to achieve my requirement using customer exit.
    Thanks in Advance,
    G S Ramanjaneyulu.

    Hi krishna,
    Thanks for your quick reply, can you have a look at my code,
    case i_vnam.
    WHEN 'ZPWK_CWK'.
    ranges : pre_week for sy-datum.
    data : start_date type DATS,
           end_date TYPE dats .
    ************FM TO GET FIRST DATE OF CURRENT WEEK ************************
    CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY'
      EXPORTING
        DATE_IN  = sy-datum
      IMPORTING
        DATE_OUT = start_date.   " WEEK FIRST DATE
    end_date = START_DATE + 6.   " WEEK LAST DATE
    END_DATE   = START_DATE - 1.   " PREVIOUS WEEK END DATE
    START_DATE = START_DATE - 7.   " PREVIOUS WEEK START  DATE
    **********PREVIOUS WEEK DATES IN PRE_WEEK******************
    pre_week-SIGN   = 'I'.
    pre_week-option = 'BT'.
    pre_week-LOW    = START_DATE.
    pre_week-HIGH   = END_DATE.
    APPEND  pre_week.
    CLEAR : START_DATE,END_DATE.
    endcase.
    Regards,
    G S Ramanjaneyulu.

  • I recently upgraded to iWork v9.0.3, but when I access each applications the versions are different (i.e. Pages V.4.1, Numbers V2.6, Keynote V5.1.1) with a install date of 3/18/09 -- which is not the current install date of 2 weeks ago. Why?

    I recently upgraded to iWork v9.0.3, but when I access each applications the versions are different (i.e. Pages V.4.1, Numbers V2.6, Keynote V5.1.1) with a install date of 3/18/09 -- which is not the current install date of 2 weeks ago. Shouldn't Pages, Numbers, and Keynote show version 9.?? My MAC confirned installation of v9.0.3 and even accepted the software code. With this discrepancy, how can I determine if the latest was installed and operational? I even downloading v9.0.4, 9.0.5, and 9.1. When I tried installing these downloads it popped up note stating that a later version of Keynote was already installed.

    You used the data.  Verizon can not see what it was sued for.  However your phone can see whats apps used the data.  go to settings-data usage- there will be a place that says data usage cycle.  line the dates up with your cycle.  then there will be a bar graph below that   extend bother white bars one all the way to the left and one all the way to the right.  after those are extended below that will be a list of apps,  there should be one that used over 2 gb and that will show you what app used that data in her purse

  • How do I change the start date for the week from Monday to Sunday on my iPhone 5?

    How do I change the start date for the week on iCal from Monday to Sunday on my iPhone5?

    Yes. On my new iPhone 5 the iCal week begins on a Monday not a Sunday and does not give me the option to edit in settings on the phone

  • I can´t view any PDF-files. Nothing happens when I click on a PDF-file. For some weeks ago we installed Adobe CreativeSuite6 on my computer. What should I do?

    For some weeks ago we installed Adobe CreativeSuite6 on my computer. What should I do?

    Hi Daniel ,
    What happens when you try to open a PDF ?
    Are you facing challenges with all the PDF' or any specific one?
    Please refer to the following link for more information regarding the same .
    Let us know how it goes.
    https://helpx.adobe.com/acrobat/kb/cant-open-pdf.html
    Regards
    Sukrit Dhingra

  • Need Monday and Friday  dates for 12 weeks.

    Hi All,
    I need a core java class which takes a curdate as argument and gives the oupt put as only monday and friday dates from that date for 12 weeks.
    For example..if u enter the date 07/06/2005.
    The ou put:
    07/06/2005 07/08/2005 and it should skips the sat&sunday.
    o7/11/2005 07/15/2005
    07/18 -07/22
    07/25 -07/29
    08/01 -08/05
    08/08 -08/12
    08/15 -08/19
    like this why because i need to diplay the data in the form of buckets.between these dates.Please help.

    Take a look at java.util.Calendar. It has all the methods you need to make your own class for this.

  • No data for a week now, why?

    I just came to Verizon a week ago. I got the Droid Razr for my wife and i had to order the Razr Maxx for me. Well i took some time to get my phone but once i did i had it one day and the next we had no data service. Both our phones have no data and sometimes 1x or 3g shows up but will disapper right after. I was told it was a service outage, well thats fine but a week later it is not fine. The thing that really gets me is that four of my co workers have Verizon and they have 3g. One has a Droid Bionac and the others have non smartphones. I get no answer from Verizon, i have called and went through the steps and then they say they will call back in four hours and get an update from me but they don't. I"m just getting very angry and i don't understand why i cant be told whats going on. I would also like to know why it seems the Razr's are the only ones with this problem. I need data for work and if this is what i have to put up with i might have to move on. I really would like to give verizon a chance but this is getting old. Is anyone else having these problems. Oh yeah i live in WV by the way.

    Hello Heifitz
    Having to wait a week for data coverage would be very upseting.  Let's get this fixed as soon as possible.
    Are you still experiencing the issue? What is your current zip code? Please remove the Sim card and reinsert. Is Wifi turned off?  If not please turn Wifi off and retest. Please power the device on in safe mode and retest. This will rule out any application that could be interfering. Here's how to power on in safe mode:
    Power Off the device
    Power On the device
    As soon as DROID Eye screen displays, press and Hold both Volume Up & Volume Down keys (Keep pressed until you reach Idle screen)
    Then the main screen will display "Safe Mode"
    Please let me know if this helps
    Thank you
    JoeL_VZW
    Please follow us on twitter @vzwsupport

  • BW reporting question (want to break down the data for 13 weeks)

    Hi All,
    I am building one report in BEx and in that report I need to calculate the data for last 13 weeks.
    What I want here is to breakdown the OTD to CT2R%   and Average delta for 13 weeks.  I mean I want to repeat the same calculation for 13 weeks.
    How can I repeat this calculation and how can I restrict per week.
    OTD to CT2R  (On time delivery to Cycle time to replenish)
    See below the template of my report.
                                  week 1                                   week 2
    Item    OTD to CT2R%    Average delta   OTD to CT2R%   Average delta
    x                 x                      x
    Thanks,
    Kam

    hi, usaully production system will be non changeable for all objects.. but as far as SAP BW is concerned we can make certain objects changeable by setting as follows..
    in production go to RSA1 - Transport Connection, select Object changeability button from tool bar, here you will find a list of objects which can be made changeable in a closed system.. just click on required objects and set it to Everything Changeable..
    Reg,
    Pradhiba
    <REMOVED>

  • Autofill dates for a week based on date selected...

    If I have a table that has Monday-Friday on it and I want to select the date on Monday and have it fill in the dates for the rest of the week, how would I do that. Or is there a way so that when it is opened on Monday, it inputs the date into the cell for Monday, then on Tuesday when it is opened, it inputs the date into the cell for Tuesday without changing the date in Monday's box? Either way is fine with me. Thanks!

    Here's a sample. https://workspaces.acrobat.com/?d=bWS4uDJgJKsWM8USbHsuKg
    In the Week Ending field you select the date - in this case it is checking to make sure that a Saturday is selected. From there it fills in the dates for the fields.

  • List of dates for a week

    Hi,
    i´m looking for a way to get the list of dates for a specific week.
    i.e.
    Week 41.2007 returns
    08.10.2007
    09.10.2007
    10.10.2007
    14.10.2007
    Any suggestions how to do this?

    that all depends on your definition of a calendar.
    does the 1st week of the year start on Jan 01? or
    does it start on the sunday of the week (sun-sat)
    that contains Jan 01? or do you use a mon-sun
    calendar instead?I didn't think it depends on the definition of the calender since weeks run indepenant from the calender year. However we are talking about a calender week. There is an iso-definition for it, which is also implemented by Oracle.
    Week number
    Weeks in a Gregorian calendar year can be numbered for each year. This style of numbering is commonly used (for example, by businesses) in some European and Asian countries, but rare elsewhere.
    Straight from Wikipedia:http://en.wikipedia.org/wiki/Week#Weeks_and_the_calendar_year
    ISO 8601 includes the ISO week date system, a numbering system for weeks; each week is associated with the year in which Thursday occurs (so that if a year starts in a long weekend Friday–Sunday, week one of the year will start after that). Thus, for example, week 1 of 2004 (2004W01) ran from Monday 29 December 2003 to Sunday, 4 January 2004. The highest week number in a year may be 52 or 53.
    The numbering system in different countries may deviate from the international ISO standard. There are at least six possibilities[2] [3]...
    >
    so, as per the OPs question, my solution is perfect.No it was not. But mine was neither. OP gave the example for 2007 but never said it will always be this year. Just like OP gave example of 41 as the week.
    -snip-
    so the 7 days would then be:
    trunc( to_date('01-jan-'|| any_year, 'dd-mon-yyyy'),
    'D' ) + ( week_num-1 )*7This is much better than my version!

  • ASCP Planned orders recommendation date for current week

    Dear Experts,
    I am facing the below issue in Decentralized ASCP workbench.
    In the forecast demand date is 18-04-11, 25-04-11, 02-05-11 and so aon (Weekly buckets).
    After launching plan today (18-04-11), Recommendation in workbench are showing due dates as 19-04-11, 25-04-11, 02-05-11 and so on.
    The question here is, Why the current week demand is shifting one day (19-04-11). Business requirement is today (18-04-11).
    Appreciating your valuable soluation.
    Note:
    (We checked planning time fence. Items having the value 0, 1 are also giving the same result)
    Regards,
    Ramesh

    Sandeep Gandhi,
    Yes, ASCP can not schedule anything in the past but it will suggest planned orders for today (Plan run date) for the past demands.
    Example: Forecast Demand due date : 16-04-11.
    when we run the plan today, ASCP have to suggest planned order for today's due date (18-04-11)
    But we don't know why it is shifting to 19-04-11 (tomorrow).
    Your valuable suggests will be very helpful
    Regards,
    Ramesh

  • How to calculate start date and last date for current week

    Dear All.
    i want to calculate the start of the current week as well as the last date of the current week, our week start from Saturday and ends of Friday i.e. Saturday is the first day of the week and Friday is the last day of the week.
    How can i acheive this in universe Designer?.
    Please help...

    Hi
    the formulas in webi will be as follows
    for startdate
    =RelativeDate(LastDayOfWeek(CurrentDate());-8)
    for enddate:
    =RelativeDate(LastDayOfWeek(CurrentDate());-2)
    Regards,
    Ranganath

  • Query to get data for current week+13

    Hi Friends,
    I have two tables
    BACKLOG_WEEK_AFTER_ATP (LE)
    BACKLOG_ATP_GT_CW (RE)
    ** First I have to query whats the current week and year and it should come in this format ---- 2011-WK30
    columns in table BACKLOG_WEEK_AFTER_ATP are:
    ITEM_NUMBER      QUANTITY
    1N5418                 20
    1N5614                 30
    1N5806SM               10
    1N5811                  0
    2PFF6                  60columns in table BACKLOG_ATP_GT_CW are:
    ITEM_NUMBER     QUANTITY        YEAR_WEEK
    1N5418                30        2011-WK30
    1N5418                 5        2011-WK31
    1N5614                30        2011-WK32
    1N5806SM              30        2011-WK33
    1N5811                20        2011-WK32
    3EX473K1              20        2011-WK30My report should look like
    ITEM_NUMBER    2011-WK30  2011-WK31  2011-WK32  2011-WK33  ...............till 13th week
    1N5418                10         -5         -5         -5  ...............till 13t week
    1N5614                30         30          0          0  ................till 13th week
    1N5806SM              10         10         10         20  ................till 13th week
    1N5811                 0          0         20         20  ................till 13th week
    2PFF6                 60         60         60         60  ................till 13th week
    3EX473K1              20         20         20         20  ................till 13th weekTo get this report i have these conditions to keep in mind.
    1) If item_number not present in LE table and present in RE table then repeat what it is in RE table till 13th week
    2) If item_number not present in RE table and present in LE table then repeat what it is in LE table till 13th week
    3) If item_number present in LE and also present in RE table then do subtraction for RE - LE for that particular item_number till 13th week.
    4) If item_number is there in LE table but not present in RE table for current_week+1(today week comes as 29th week) then repeat the same which is there in LE table. If item is found in RE table for (example 32th week) then subtract RE -LE for that particular item_number
    Thanks in advance.
    Regards

    Hello,
    If you don't need the PIVOT display, then this may help you :
    with le as
    (select '1N5418' item_number, 20 quantity from dual union all
    select '1N5614' item_number, 30 quantity from dual union all
    select '1N5806SM' item_number, 10 quantity from dual union all
    select '1N5811' item_number, 0 quantity from dual union all
    select '2PFF6' item_number, 60 quantity from dual ),
    re as
    (select '1N5418' item_number, 30 quantity, '2011-WK30' year_week from dual union all
    select '1N5418' item_number, 5 quantity, '2011-WK31' year_week from dual union all
    select '1N5614' item_number, 30 quantity, '2011-WK32' year_week from dual union all
    select '1N5806SM' item_number, 30 quantity, '2011-WK33' year_week from dual union all
    select '1N5811' item_number, 20 quantity, '2011-WK32' year_week from dual union all
    select '3EX473K1' item_number, 20 quantity, '2011-WK30' year_week from dual
    row_gen as (
    select item_number, calc_year_week,
           row_number() over(partition by item_number order by calc_year_week) rn
    from
        (select le.item_number from le union select item_number from re) item,
        (select to_char(level*7+sysdate,'YYYY-"WK"WW') calc_year_week from dual connect by level<=13) week)
    select item_number, calc_year_week, calc_qty
    from row_gen, le, re
    where row_gen.item_number=le.item_number(+)
    and row_gen.item_number=re.item_number(+)
    and row_gen.calc_year_week=re.year_week(+)
    model
    partition by (row_gen.item_number)
    dimension by (rn)
    measures (calc_year_week, year_week, le.quantity le_qty,re.quantity re_qty,0 calc_qty )
    rules  (
    calc_qty[1]  =
        case when re_qty[cv()] is null then le_qty[cv()]
        when le_qty[cv()] is null then re_qty[cv()]
        else  re_qty[cv()]-le_qty[cv()]
    end,     
    calc_qty[rn>1] order by rn =
        case when re_qty[cv()] is null then calc_qty[cv()-1]
        else re_qty[cv()] - calc_qty[cv()-1]
        end           )
    order by 1,2;I am not sure this is the simplest way to do it, but the results seem to match your example.
    Regards,
    Sylvie
    Edited by: Troll35 on Jul 19, 2011 3:08 PM

  • Query - to calculate data for previous year

    Hi forum,
    I have a requirement to calculate
    ' Total number of complaints received current month last year / total number of complaints last year)*current year total complaints target.'
    I have no of complaints as key figure.
    Any ideas how to do it in query designer.
    Thanks in advance.
    Regards,

    Hi,
    The requirement is user will select the month he wants to see the records.
    Based on input I have to calculate
    1. Records from same month previous year.
    2. Total records last year and
    3. Total records this year.
    I just need 1 input variable. Please explain in detail.
    Should i create 2 RKF for records of previous year and for records of this year.
    regards

Maybe you are looking for