Generating the last day of the week

HI All,
I have the Year value (for eg 2002, 2006) and the week number value in the year ( for eg : 32, 52) . Based on this information, how can I get the last day of the particular week.
for eg What is the last day of the week - 2002,32
Any pointer would be great.
Thanks and Regards
Venkat

Or try this:
SQL> WITH t AS
     (SELECT 2006 YEAR, 1 week
        FROM DUAL
      UNION ALL
      SELECT 2002 YEAR, 32 week
        FROM DUAL
      UNION ALL
      SELECT 2005 YEAR, 52 week
        FROM DUAL
      UNION ALL
      SELECT 2006 YEAR, 52 week
        FROM DUAL)
SELECT YEAR,
       week,
       CASE
          WHEN TO_CHAR (TRUNC (TO_DATE (YEAR, 'RR'), 'RR'), 'IW') != 1
             THEN TRUNC (TRUNC (TO_DATE (YEAR, 'RR'), 'RR') + 7, 'IW')
          ELSE TRUNC (TRUNC (TO_DATE (YEAR, 'RR'), 'RR'), 'IW')
       END
       + 6 + (week - 1) * 7 LAST_DAY
  FROM t
                                              YEAR                                               WEEK LAST_DAY
                                              2006                                                  1 08-JAN-06
                                              2002                                                 32 11-AUG-02
                                              2005                                                 52 01-JAN-06
                                              2006                                                 52 31-DEZ-06
4 rows selected.

Similar Messages

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

  • To calculate the last day of a week

    I have this problem.
    I must calculate the last day (saturday) of a week, if I have somewhere day of a week.
    For example
    if today is Thursday 08/03 how can calculate Saturday 10/03?
    Thank's a lot!!!

    The day number given previously is territory dependant. So, in France, the last day of week (day 7) is sunday instead of saturday...
    You can try to work with next_day function, which is more independant :
    SQL> select to_char(sysdate,'d') from dual;
    T
    4
    SQL> select next_day(sysdate-1,'saturday') from dual;
    NEXT_DAY
    10/03/07
    SQL> alter session set nls_territory='america';
    Session altered.
    SQL> select to_char(sysdate,'d') from dual;
    T
    5
    SQL>
    SQL> select next_day(sysdate-1,'saturday') from dual;
    NEXT_DAY(
    10-MAR-07
    SQL> Nicolas.

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

  • Find the first and last day of week giving a certain date

    Hi,
    i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?
    Many thanks in advance,
    Nuno Almeida

    nfalmeida wrote:
    i have an application in wich the user puts a date, say today 2010-08-10 and i have to calculate first and last day of that week, in this case 2010-08-09 and 2010-08-15. How can i do this?First step is being sure that you know what a 'week' is.
    For example does it really start on monday? And will it always start on monday?
    And what day does the 'week' end on for 2010-12-29? In some businesses it will end on 2010-12-31 (friday)

  • UDF for last day of week/month

    Input is a Date(For example: 2010/03/12) in String  format.
    I need to extract the last day of that week and return it as a string output.
    For example if input is 2010/03/12 and thatu2019s a Thursday my output should be 2010/03/14 i.e Saturdayu2019s date.
    Similarly I need to extract last day of month too.
    Thanks in advance
    Soumen...

    Hi,
    I did not develop this one... but just use "search" button on roseindia and you will have the answer (I think):
    [http://www.roseindia.net/java/beginners/DayOfYearToDayOfWeek.shtml|http://www.roseindia.net/java/beginners/DayOfYearToDayOfWeek.shtml]
    and do not forget that Google is your friend...
    do a research with : Java last day of week, and you have plenty of examples.
    Thanks.
    P.S: Say us when you will solved your problem.

  • Ios 5 Update New Features says that iCal now has a week view for iPhone but after updating last weekend, I don't see any week view--just List, Day and Month..How do I get the week view?

    ios 5 Update New Features says that calendar now has a week view but after updating my iPhone 4 last weekend, I don't see any week view for iCal--just List, Day and Month as in the past. Is the weekly view available for iCal and if so, how do I access it?

    Rotate your phone to landscape.

  • Weekly schedule line should pass to last working day of the week in SAg

    HI,
    In a scheduling agreement when we have weekly or monthly schedules the system displays the date in the screen as 12/2010 or 13/2010 for say a weekly schedule.
    However when the data is stored in the table the delivery date is always the first working day of the week. In this case when the week is 13/2010 the data is stored in the table as 22/03/2010.
    Is there any way to change this to the last working day of the week?
    We have some config related to define delivery intervals in IMG--> Sales and Distribution --> Sales --> Sales Documents --> Scheduling Agreements with Delivery Schedules --> Define Delivery Intervals. Will this help solve my issue? If it solves what is the procedure behind this?
    Request you to provide your inputs.
    Thank You, Lakshmikanth

    Hi,
    Seems the delivery split concept is different from this requirement. Can Delivery intervals concept help us or not? IMG--> Slaes and Distribution --> Sales --> Sales Documents --> Scheduling Agreements with Delivery Schedules --> Control EDI Inbound Processing --> Define Delivery Intervals.
    What is the procedure and assignment details for delivery intervals concept?
    Thanks, Lakshmikanth

  • Getting the Last day for a given week number

    Dear Gurus,
    I want to find the Last day of a given week number.
    Can anyone help me out.
    Regards
    Madhu K

    Here I dont want to pass date,
    If I give Week Number, Can I get that Week Numbers
    Last date and First Date.
    test@ORA10G>
    test@ORA10G> -- this query fetches the start and end dates for a specified week in the current year
    test@ORA10G>
    test@ORA10G> select
      2    wk as week,
      3    min(dt) as start_date,
      4    max(dt) as end_date
      5  from (
      6    select
      7      trunc(sysdate,'yyyy')+level-1 as dt,
      8      to_char(trunc(sysdate,'yyyy')+level-1,'ww') as wk
      9    from dual
    10    connect by level <= trunc(add_months(sysdate,12),'yyyy') - trunc(sysdate,'yyyy')
    11  )
    12  where wk = &week_number
    13  group by wk;
    Enter value for week_number: 1
    WE START_DAT END_DATE
    01 01-JAN-08 07-JAN-08
    test@ORA10G>
    test@ORA10G> /
    Enter value for week_number: 23
    WE START_DAT END_DATE
    23 03-JUN-08 09-JUN-08
    test@ORA10G>
    test@ORA10G> /
    Enter value for week_number: 52
    WE START_DAT END_DATE
    52 23-DEC-08 29-DEC-08
    test@ORA10G>
    test@ORA10G> /
    Enter value for week_number: 53
    WE START_DAT END_DATE
    53 30-DEC-08 31-DEC-08
    test@ORA10G>
    test@ORA10G>pratz
    can be shortened further:
    test@ORA10G>
    test@ORA10G> select
      2    to_char(trunc(sysdate,'yyyy')+level-1,'ww') as wk,
      3    min(trunc(sysdate,'yyyy')+level-1) as start_dt,
      4    max(trunc(sysdate,'yyyy')+level-1) as end_dt
      5  from dual
      6  where to_number(to_char(trunc(sysdate,'yyyy')+level-1,'ww')) = &week_number
      7  connect by level <= trunc(add_months(sysdate,12),'yyyy') - trunc(sysdate,'yyyy')
      8  group by to_char(trunc(sysdate,'yyyy')+level-1,'ww')
      9  /
    Enter value for week_number: 1
    WK START_DT  END_DT
    01 01-JAN-08 07-JAN-08
    test@ORA10G>
    test@ORA10G> /
    Enter value for week_number: 53
    WK START_DT  END_DT
    53 30-DEC-08 31-DEC-08
    test@ORA10G>
    test@ORA10G> /
    Enter value for week_number: 23
    WK START_DT  END_DT
    23 03-JUN-08 09-JUN-08
    test@ORA10G>
    test@ORA10G> /
    Enter value for week_number: 14
    WK START_DT  END_DT
    14 01-APR-08 07-APR-08
    test@ORA10G>
    test@ORA10G>Message was edited by:
    pratz

  • Find first & last day of the week from given date

    Hi All,
    I have the below input query,
    WITH TEM AS   ( SELECT '11-JAN-13' DT from dual union   SELECT '16-JUN-12' from dual union   SELECT '04-JUL-12' from dual union   SELECT '09-JAN-13' from dual union   SELECT '10-JAN-13' from dual union   SELECT '04-JAN-13' from dual union   SELECT '07-JAN-13' from dual union   SELECT '04-JUN-13' from dual union   SELECT '08-JAN-13' from dual )  SELECT TO_DATE(DT) D1,'WEEK '||TO_CHAR(TO_DATE(DT),'IW-YYYY') WK from tem;
    I would like to get the below output i.e. Starting date of the week(Saturday) & end date of the week(Friday)
    DT
    WEEK Period
    Max Date in this week
    Min Date in this week
    16-Jun-12
    WEEK 24-2012
    16-Jun-12
    22-Jun-12
    04-Jul-12
    WEEK 27-2012
    30-Jun-12
    06-Jul-12
    04-Jan-13
    WEEK 01-2013
    04-Jan-13
    29-Dec-12
    07-Jan-13
    WEEK 02-2013
    05-Jan-13
    11-Jan-13
    08-Jan-13
    WEEK 02-2013
    05-Jan-13
    11-Jan-13
    09-Jan-13
    WEEK 02-2013
    05-Jan-13
    11-Jan-13
    10-Jan-13
    WEEK 02-2013
    05-Jan-13
    11-Jan-13
    11-Jan-13
    WEEK 02-2013
    05-Jan-13
    11-Jan-13
    04-Jun-13
    WEEK 23-2013
    01-Jun-13
    07-Jun-13
    Also suggest if any function available in oracle for this one.

    Like this? I think in your required output, 3rd row data, MAX_DATE should be 29-DEC-12 and MIN_DATE should be 04-JAN-13.
    WITH TEM AS 
    ( SELECT '11-JAN-13' DT from dual union 
    SELECT '16-JUN-12' from dual union
    SELECT '04-JUL-12' from dual union
    SELECT '09-JAN-13' from dual union
    SELECT '10-JAN-13' from dual union 
    SELECT '04-JAN-13' from dual union
    SELECT '07-JAN-13' from dual union
    SELECT '04-JUN-13' from dual union
    SELECT '08-JAN-13' from dual )
    SELECT D1 DT,
           WK WEEK_PERIOD,
           CASE WHEN (TRIM(TO_CHAR(D1,'DAY'))='SATURDAY') THEN D1
                 ELSE NEXT_DAY(D1,'SATURDAY')-7
            END AS MAX_DATE_IN_THIS_WEEK,
          CASE WHEN (TRIM(TO_CHAR(D1,'DAY'))='FRIDAY') THEN D1
                ELSE NEXT_DAY(D1,'FRIDAY') END AS MIN_DATE_IN_THIS_WEEK
    FROM (
    SELECT TO_DATE(DT) D1,'WEEK '||TO_CHAR(TO_DATE(DT),'IW-YYYY') WK from tem)
    ORDER BY DT;
    OUTPUT:
    DT        WEEK_PERIOD  MAX_DATE_ MIN_DATE_
    16-JUN-12 WEEK 24-2012 16-JUN-12 22-JUN-12
    04-JUL-12 WEEK 27-2012 30-JUN-12 06-JUL-12
    04-JAN-13 WEEK 01-2013 29-DEC-12 04-JAN-13
    07-JAN-13 WEEK 02-2013 05-JAN-13 11-JAN-13
    08-JAN-13 WEEK 02-2013 05-JAN-13 11-JAN-13
    09-JAN-13 WEEK 02-2013 05-JAN-13 11-JAN-13
    10-JAN-13 WEEK 02-2013 05-JAN-13 11-JAN-13
    11-JAN-13 WEEK 02-2013 05-JAN-13 11-JAN-13
    04-JUN-13 WEEK 23-2013 01-JUN-13 07-JUN-13
    9 rows selected.

  • Calendar crashes -  Monday as 1st day of the week

    I have an ipad1, running iOS 5.1.1. It's sync to iCloud. I deleted entries to Sept 1. It was stuck on month view of September. I couldn't change it to another month or view.
    I soft reset. no change.
    I hard reset. no change.
    I factory reset and restored iPad with Itunes and restored old settings. no change.
    I factory reset iPad with iTunes as new ipad. Calendar was behaving.
    I went into settings and personalised it.
    It's is now September. when I click on September month view Calendar crashes. Other views are ok. Month view of other months is ok.
    Then I realised that to have a the month view starting on Monday as the first day, I have the general>international>region format set as UK (I'm in Australia). When I set it back to Australia, then Calendar doesn't crash.
    So the factory reset served to reset the region to my local region.
    The work around for Apple changing the Calendar start day to Sunday was to change the region to one where the start day was Monday. It had been working fine until recently. I'm not sure when the crashing started happening, perhaps on the last iOS update.
    So, it may have been that a mismatch in local region to region designated on the settings that crashes the Calendar. It may be that selecting UK crashes the Calendar.
    Now, Calendar crash problem solved. This might help someone else with the same problem.
    Calendar format starting on unpreferred day reintroduced.
    I would like to see my month view start the day as Monday, not Sunday. Does anyone have a solution?

    Thanks .
    I've managed to fix it:
    Go to Settings / Mail Contacts and Calendars / Start the week on
    Change from Sunday to Monday.
    It appears people in Brazil are the only ones affected.
    It's a good work-around  while apple does not fix this bug.
    https://discussions.apple.com/message/23578143#23578143#23578143

  • Report Request - Tickets by day of the week

    So there are plenty of reports that show data based on past X days, but as far as I can see, none break it up into by days of the week.
    Example, For the last month, how many tickets were closed on Monday, Tuesday, by what Tech, in which Category/Location/Custom attribute.
    Could someone better than I make this happen?
    This topic first appeared in the Spiceworks Community

    I am not sure about your help.  Text variable is part of the header of a column and how is it possible to use the text variable as part of the result area.  I want the day to be part of the line item in the report.
    Appreciate if any one can provide their thoughts and input.
    Regards
    Sundar

  • How do I set a reminder for the last day of every month

    Have I missed something? But how do you set a reminder for the last day of every month to recurr indefinatley in iOS6? Sorry if this is really simple but I just can't seem to work it out. Any help gratefully received.

    Hey Mattye88 not sure if you have seen but actully you can do this, but for some reason you have to use Siri.  If you bring up Siri and say "set a reminder ever 4 weeks from next wednesday to check the gas meter" it will set one and it will work just fine, I have reminders to water a Bonsai every three days and it works fine it just shows as custom repeat on the user interface.  Alas it seems you can not use Siri to set one for the end of the month though which is why I am in this threed.  Still hope it helps you to know how to sort this problem atleast.

  • How to return the week number starting from Sunday as the first day

    Hi Friends,
    My application needs to have a report for the weekly totals and must have the Sunday as the first day for the week. For example, January of 2005 should be in the report for having six weeks, Jan 1 is Saturday, this is week 1, Week 2 is from 2 to 8, and the last week , week 6 has 30 and 31. Days need not be displayed, only the week number as follows:
    Week Number Total Sales
    =========== =========
    Week 1 8,525
    Week 2 8,168
    Week 3
    Week 4
    Week 5
    Week 6
    The discoverer hierarchies function for week (eul_date_trunc(item_date, '"W"W')) seems to start the week from the first day of the month regardless of the day. Oracle function TO_CHAR(item_date, 'W') does the same thing, .As the result, the January of 2005 has only 5 weeks.
    Any help or advice for this issue will be greatly appreciated.
    Thank you very much,
    J.K

    Try this
    ---------------------------------------------actual formula---------------
    select ceil(
    ( to_number(to_char(to_date('1-'||to_char(sysdate,'MON-YYYY'),'DD-MON-YYYY'),'D')) -1
    + to_number(to_char(sysdate,'DD'))
    ) / 7
    week_number
    from dual
    e.g try different dates below by replacing 31-Jan-2005
    select ceil(
    ( to_number(to_char(to_date('1-'||to_char(to_date('31-JAN-2005'),'MON-YYYY'),'DD-MON-YYYY'),'D') ) -1
    + to_number(to_char(to_date('31-JAN-2005'),'DD'))
    ) / 7
    week_number
    from dual
    How does it work
    week number is calculated by dividing the current day number by number of days
    so in your case if the week starts at a different day , you just add the offset and divide by 7
    In the first part, i am finding the week day number for the 1st day of the current month and this is used as offset.
    Hope this helps
    -nj
    http://www.infocaptor.com

  • Figure out dates corresponding to days of the week, constructing a schedule

    Hi everyone,
    I'm sorry if this topic has already been covered. I've searched the forums for an answer, but did not see anything I took to be an answer (I'm not very good at this).
    I'm trying to make a simple table to tell me which dates a particular day of the week falls on. For instance, I'm making a syllabus for a class that meets every Tuesday and Thursday. I want to know which dates corresponds to every Tuesday and Thursday from here on out.
    I currently have a table with two columns. The first column is the day of the week. The first row is Tuesday, the second is Thursday, the third Tuesday, etc. I was able to do this easily with auto fill. I want the next column to be the date.
    Here's a picture of what I mean:
    Is there a formula that will let me do this?
    Thanks!

    Hi Macademic,
    How about putting both into the first column?
    Select all of column A and use the Cell Format inspector to set the format as Date and Time, with the Date: and Time: pop-up menus set to:
    Date: Mon, Jan 5, 2009
        or: Monday, January 5, 2009
        or  to a Custom format, Date and Time, including only the elements you want in the format you want them.
    Time: None
    Enter the starting date into A2, and confirm that it is either a Tuesday or a Thursday.
    In A3, enter
    =A2+2 (if the course starts on a Tuesday)
    or
    =A2+5 (if the course starts on a Thursday)
    In A4, enter
    =A2+7
    Select A3 and A4, then grab the control (small circle at the lower right corner of the selection) and drag down until you reach the last date of the course.
    Regards,
    Barry

Maybe you are looking for