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() );

Similar Messages

  • How to get the last day of the week?

    Hii
    i can get the calender week number for any given date using
    SELECT to_char(to_date('04/04/2011','MM/DD/YYYY'),'WW') FROM dual
    can any body tell me, how to get the last day of that week ?
    and the answer should be 04/08/2011(8th april )
    thanks
    San
    Edited by: sandeep9 on Apr 4, 2011 3:50 AM

    Hi, San,
    Here's one way:
    WITH     sample_data     AS
         SELECT  DATE '2011-04-04'     AS dt
         FROM     dual
    SELECT  dt
    ,     TO_CHAR (dt, 'WW')     AS week_num
    ,     NEXT_DAY ( dt - 1
               , TO_CHAR ( TRUNC (dt, 'YEAR') - 1
                      , 'Day'
               )          AS end_o_week
    FROM     sample_data;Another way is to use date arrithmetic:
    WITH     sample_data     AS
         SELECT  DATE '2011-04-09'     AS dt
         FROM     dual
    SELECT  dt
    ,     TO_CHAR (dt, 'WW')     AS week_num
    ,     TRUNC (dt, 'YEAR')
          + (7 * CEIL ( (dt - (TRUNC (dt, 'YEAR') - 1))
                / 7
          - 1               AS using_date_arithmetic
    FROM     sample_data;

  • How to get the last day according to fiscal period input in selection scree

    Hello expert
    how to get the last day of fiscal period input.
    the fiscal period inculdes 1-16
    when fiscal period is greater than 12, only calculate the last day of 12nd month
    your solution will be apprecaited, FM existing?
    thank you
    Kevin

    Hi,
    when you give a particular date in any month
    the following fm will give you the last date of that month
    here you can give
    R_FDATE-HIGH  as 01 and month as the period you wnat and year for current year
    concatenates '01'  month year  into r_fdate-high separated by '.'.
    then it will give g_ltdt for that month and year which wil be the last date of that month
        CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
          EXPORTING
            DAY_IN            = R_FDATE-HIGH
          IMPORTING
            LAST_DAY_OF_MONTH = G_LTDT
          EXCEPTIONS
            DAY_IN_NO_DATE    = 1
            OTHERS            = 2.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    thanks & regards,
    Venkatesh

  • How to get the last day of a month?

    HI,
    I want to know how to get the last day of a month.
    In my JClient form, I tried to get it by using oracle.sql.Date method, that is:
    lastday=oracle.sql.Date anydate.lastDayOfMonth();
    But it does not work. The result is lastday=anydate.
    Why?
    Stephen

    You can use the Calender class...
    Calendar c = Calendar.getInstance();
    and then something like...
    c.add(c.MONTH, 1);
    int dayOfMonth = c.get(Calender.MONTH);
    c.add(c.DAY_OF_MONTH, - (dayOfMonth-1) );
    other usefull functions are:
    System.out.println(" YEAR : " + c.get(Calendar.YEAR));
    System.out.println(" MONTH : " + c.get(Calendar.MONTH));
    System.out.println(" DAY_OF_MONTH : " + c.get(Calendar.DAY_OF_MONTH));
    System.out.println(" DAY_OF_WEEK : " + c.get(Calendar.DAY_OF_WEEK));
    System.out.println(" DAY_OF_YEAR : " + c.get(Calendar.DAY_OF_YEAR));
    System.out.println(" WEEK_OF_YEAR : " + c.get(Calendar.WEEK_OF_YEAR));
    System.out.println(" WEEK_OF_MONTH : " + c.get(Calendar.WEEK_OF_MONTH));
    System.out.println(" DAY_OF_WEEK_IN_MONTH : " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println(" HOUR : " + c.get(Calendar.HOUR));
    System.out.println(" AM_PM : " + c.get(Calendar.AM_PM));
    System.out.println(" HOUR_OF_DAY (24-hour): " + c.get(Calendar.HOUR_OF_DAY));
    System.out.println(" MINUTE : " + c.get(Calendar.MINUTE));
    System.out.println(" SECOND : " + c.get(Calendar.SECOND));
    System.out.println();*/

  • Object date - how to get the last day of the month?

    hi all,
    I have a date object in which I would like to get the last day of the month. any idea?
    eg AUG=31
    Feb = 28 (depends if a leap year)
    thanks

    Use java.util.Calendar
    Add 1 month to the day.
    Set the day of month to be 1.
    Subtract 1 day.
    Now you are on the last day of the month you wanted.

  • How to get the last day of the next month?

    Hi all.
    I need to get the last day of the next month. E.g. if the date is 20.03.2008 I need to get 30.04.2008.
    Is there any FM for it?
    TIA, Nikolai.

    hi Nikolai,
    pls. have a look athe following piece of code:
    PARAMETERS : p_date TYPE sy-datum.
    DATA : gv_res TYPE sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
    *   DAYS              = '0'
       months            = '2'
       start_date        = p_date
    IMPORTING
       result_date       = gv_res.
    ==> Now you have (gv_res) 2 months later as today
    gv_res+6(2) = '01'. ==> gv_res is first day of next-next month
    gv_res = gv_res - 1. ==> gv_res is last day of next month
    hope this helps
    ec

  • How to get the last day of the payroll period

    Hi all,
    I need to get the last day of the payroll period e.g. last day of Jan 2007 is 31 Jan 2007. Can anyone suggest as to how to get it?
    Thanks,
    Madhu

    T549S contains the payroll periods with pay date.  T549Q contains the begin and end dates of the payroll period.
    You can select from the appropriate table (or from both depending on your given data) to get the end date of the period.
    Hope that helps.
    Mary

  • How to get the last day of calweek

    Hi Guys,
                Is there any function module to get the last day of the calendarweek.
    I want to show that last date of calweek in my column heading.

    You can use the Calender class...
    Calendar c = Calendar.getInstance();
    and then something like...
    c.add(c.MONTH, 1);
    int dayOfMonth = c.get(Calender.MONTH);
    c.add(c.DAY_OF_MONTH, - (dayOfMonth-1) );
    other usefull functions are:
    System.out.println(" YEAR : " + c.get(Calendar.YEAR));
    System.out.println(" MONTH : " + c.get(Calendar.MONTH));
    System.out.println(" DAY_OF_MONTH : " + c.get(Calendar.DAY_OF_MONTH));
    System.out.println(" DAY_OF_WEEK : " + c.get(Calendar.DAY_OF_WEEK));
    System.out.println(" DAY_OF_YEAR : " + c.get(Calendar.DAY_OF_YEAR));
    System.out.println(" WEEK_OF_YEAR : " + c.get(Calendar.WEEK_OF_YEAR));
    System.out.println(" WEEK_OF_MONTH : " + c.get(Calendar.WEEK_OF_MONTH));
    System.out.println(" DAY_OF_WEEK_IN_MONTH : " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println(" HOUR : " + c.get(Calendar.HOUR));
    System.out.println(" AM_PM : " + c.get(Calendar.AM_PM));
    System.out.println(" HOUR_OF_DAY (24-hour): " + c.get(Calendar.HOUR_OF_DAY));
    System.out.println(" MINUTE : " + c.get(Calendar.MINUTE));
    System.out.println(" SECOND : " + c.get(Calendar.SECOND));
    System.out.println();*/

  • How to get the last day of the previous month

    Hello Team,
    If  my input date is today , then i need to find out the last day of the previous month for the same.
    Can someone help me  to find out .. how can this be done.
    Regards,
    Ravi

    Hi,
    Try the below code.
         // get a calendar object
        GregorianCalendar calendar = new GregorianCalendar();
        // convert the year and month to integers
        int yearInt = Integer.parseInt(year);
        int monthInt = Integer.parseInt(month);
         int dayInt = Integer.parseInt(day);
        // adjust the month for a zero based index
        monthInt = monthInt - 1;
        // set the date of the calendar to the date provided
        calendar.set(yearInt, monthInt, dayInt);
        int day = calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
        return Integer.toString(day);
    Regards
    Venkat

  • How to get the First day in a Week in a Fiscal Year

    Hi guys,
    I have a Requirement to calculate the First day in  a Week  in a Fiscal year .
    The FM GET*FIRST_DATE and all are for Calender year.
    Is there any FM to calculate the First in a Week in a Fiscal year.
    For eg. They will give 200826.
    In this 26 is the Week.
    I need to find the First date value in that Week.
    Thanks,
    Gokul

    Hi Gokul...
    Instead of using the funtion module you can just write the 3 statements of code to get the first day of the week.
    Its similar to the above one but instead of writing case statement you can achive the following.
    data : w_res type i,
             w_data type d,
    w_res = w_date mod 7.
    w_date = w_date - w_res.
    write w_date.
    This works.
    Regards,
    Siddarth

  • How to get the last day of the current open fiscal period?

    hi folks,
         I  have to display the last date of the current open fiscal period in the selection screen. Its just a display only.
          if there is any function module vailable for getting that period, kindly suggest me?
    thanks in advance,
    cheers,
    Adi.

    hi,
    CALL FUNCTION '/BEV3/CHPERIOD_DETERMINE'
    EXPORTING
    date = sy-datum
    version = c_version
    IMPORTING
    period = l_period
    year = l_fiscal_year
    EXCEPTIONS
    period_in_not_valid = 1
    period_not_assigned = 2
    version_undefined = 3
    OTHERS = 4.
    If not use GM_GET_FISCAL_YEAR
    CALL FUNCTION 'GET_CURRENT_YEAR'
    EXPORTING
    BUKRS = '1000' " Company Code
    DATE = SY-DATUM " Date to find fiscal year for
    IMPORTING
    CURRM = w_currm " Current Fiscal Month
    CURRY = w_curry " Current Fiscal Year
    PREVM = w_prevm " Previous Fiscal Month
    PREVY = w_prevy. " Previous Fiscal Year
    Rgds
    Anver

  • How to get the "last changed by" for a set of function modules?

    How to get the "last changed by" for a set of function modules?
    is there any table to get it??

    See [this|Re: Date of creation of function module] I posted earlier.
    >TFDIR will give you the name of the function group program and the include number.
    >E.g. SAPLZFUNCGROUP Include 01.
    >From this you can construct the include name: LZFUNCGROUPU01.
    >You can look this up in TRDIR to find the creation date (CDAT) of the function module.
    In your case, you need unam and udat.
    matt

  • How to get the last error for while loop?

    How to get the last error for while loop? I just want transfer the last error for while loop, but the program use the shift register shift all error every cycle.

    What do you mean by "get" and "transfer"?
    If the shift register is not what you want, use a plan tunnel instead.
    Typically, programmers are interested in the first, not last, error.
    Can you show us your code so we have a better idea what you are trying to?
    LabVIEW Champion . Do more with less code and in less time .

  • How to get the last version of flash in MSI format automatically?

    How to get the last version of flash in MSI format automatically?
    Roberto Neigenfind
    Bravo Tecnologia
    www.bravotecnologia.com.br

    Hi Barbara,
    Flash Professional CS5.5 is a 32-bit application which can be installed on computers with either 32-bit or 64-bit operating systems.
    You can purchase this by Adobe's backward Licensing policy :
    " Adobe allows program members to order a current-version license but use a prior version. These members can contact Adobe Customer Service to request a serial number for the earlier version if they do not already have one. Prior-version software is available via ESD and can be purchased through standard resellers. The program member must follow all guidelines of the current-version EULA. "
    Please check the doc : http://www.adobe.com/volume-licensing/policies.html

  • How to get the exact day date with the another date field?

    Hi,
    Please help me how to get the specific day of the week's date with the help of another date field.
    Actually , one field(week_day) has 1,2,3,4,5,6,7 here 1--MON,2-- TUE like that.
    another field has the date. based on that date, we have to go to that particular week and need to pick up the date by the above week_day. It should be in that week itself.
    Thanks in advance!!
    Regards,
    Vissu...
    Edited by: vissu on Oct 29, 2010 3:07 AM

    Hi,
    Something like this
    SELECT TRUNC(<DATE_COLUMN>,'DAY')+<WEEK_NO_COLUMN> FROM <YOUR_TABLE>;for the particular week of the date
    SELECT TRUNC(SYSDATE,'DAY')+<WEEK_NO_COLUMN> FROM <YOUR_TABLE>;for the current week
    cheers
    VT

Maybe you are looking for