Week to date

Dear All,
It is no problem to convert a date to get the week number:
TO_CHAR(sysdate, 'YYYYIW')
But what I need to do is to go the other way and generate the date of the Monday for that particular week.
With a month and the TO_DATE command this would be no problem. And from my googling I see that there are procedures available that will do what I need.
But my question is whether I am able to do this conversion with an in-built Oracle function? Or do I need to incorporate PL/SQL?
Any tips would be gratefully received.
Regards and thanks,
Alan

Hi, Alan,
Alan Searle wrote:
Dear All,
It is no problem to convert a date to get the week number:
TO_CHAR(sysdate, 'YYYYIW')You mean '<b>I</b>YYYIW', don't you?
But what I need to do is to go the other way and generate the date of the Monday for that particular week.
With a month and the TO_DATE command this would be no problem. And from my googling I see that there are procedures available that will do what I need.
But my question is whether I am able to do this conversion with an in-built Oracle function? Or do I need to incorporate PL/SQL?You don't need PL/SQL, but when you see how many functions you have to call to do what should be a simple task, perhaps you'll want it.
Assuming you have a string like '201002' meaning 'week 2 of ISO year 2010', the following query tells you when that week started:
SELECT     TRUNC ( TO_DATE ( SUBSTR (:iyw, 1, 4) || '0131'
               , 'YYYY'            || 'MMDD'
           , 'IYYY'
     + ( 7
       * ( TO_NUMBER ( SUBSTR (:iyw, 5))
         - 1
       )     AS iyw_monday
FROM     dual
;The following is one way to get such a string, which you can use for testing:
VARIABLE  iyw     VARCHAR2 (6)
EXEC     :iyw := '201002';The ISO year may begin a few days into January, but never as late as January 31. The query above uses January 31 as a date that is guaranteed to be within the same calendar year and ISO year, so we can use TO_CHAR (..., 'YYYY') to turn the string into a DATE, and then TRUNC (..., 'IYYY') to find the beginning of the ISO year.

Similar Messages

  • Group by week between date range

    Hi,
    i'm having a table for documents. The documents are received from diffeent dates. I've to calculate number of documents received on weekly basis.
    I need an sql to count the number of documents between two given dates grouping by weekly.
    My week starts on Sunday and ends with Saturday.
    I've tried group by with to_char(documentdate,'IW') , but this will take Monday to Sunday as a week & the incomlete weeks i'm not able to calculate. ie : in the below output the date range 1/28/2007 - 1/31/2007 is not a complete week . ( ie saturday to wednesday)
    I need out put should be like this for Date Range: 12/31/2006 to 1/31/2007
    week               count of documents
    12/31/2006 - 1/6/2007 10
    1/7/2007 - 1/13/2007     40
    1/14/2007 - 1/20/2007     30
    1/21/2007 - 1/27/2007     20
    1/28/2007 - 1/31/2007 10
    Please help me to get this.....
    (columns in documents table is documentid and documentdate)

    your're very close with IW. you just need to shift the data to get it to fall within the correct range. btw, you don't need julian dates. it's overkill
    trunc(date+1,'IW') will push the date into the correct week range (IW will put sunday one week earlier than you want, so push it ahead a day before truncating).
    then subtract 1 day from the result to get it to display with sunday's date instead of monday
    trunc(mydate+1, 'IW')-1
    and the week end date is simply trunc(mydate+1, 'IW')_5
    select mydate, to_char(mydate,'Dy') dy,
    trunc(mydate+1,'IW')-1 wk_Start,
    trunc(mydate+1,'IW')+5 wk_end
    from (select sysdate-rownum mydate from dual connect by level < 20)
    order by 1

  • Default selection on current month, week and date

    Hi,
    We are on Dashboard 4.1 sp3 the same version as BI.
    The dashboard report is using LiveOffice connection. We are now facing an issue with default selection on current month, week and date.
    The dashboard report drilled down from month, to week, then to date. The dashboard feed -live office report is on month/week/date ascending order - becuase we have running average calcualtion on LO report, it seems have to be in ascending order to get the correnct runnning average.
    I tried to on Insertion to change default seletion, it works on month, but it doesnt working on week and daily.
    but when LO report is on ascending order, on dashboard column chart the default selection is not on the current month, week and date.
    Is there a way to solve the issue. Could anyone please help.
    Thanks,

    Hi Suman,
    Thanks for the quick reply.
    Do you mean I Enable sorting -by categrory labels on Behaviour - common tab.
    Thanks,

  • How to get the day of 52 weeks ago data

    hi all:
    i recently encounter the difficulty that using the current data to get the 52 weeks ago data in essbase.the fct table is like this:
    current_dt the_day_of_week sales
    20110203 5dw05 100
    20100207 5dw05 30
    note: "5dw05" means the fifth day of five week in the selected year
    the question is which essbase formula to choise or how to use them in essbase outline structure can meet the bussines role that when the biz men chlic on the member "20110203" of time dimension, the extension mesure "bf_sales" value is 30.
    the outline i am about to design under the bellow:
    dim_time
    201002
    20110201(alias 4dw05)
    20110202(alias 5dw05)
    20110203(alias 6dw05)
    201102
    20110206(alias 4dw05)
    20110207(alias 5dw05)
    dim_measure
    sales
    bf_sales(will use the essbase formula,but do not know which function to choise or how to use it)
    i am lovely hope one of you may give me suggestion on this issue. thanks a lot for all of you!

    If you put the Apple calendar app on the first screen, it shows the day and date (no month/year). E.g Sunday 20.

  • Get week ending date from Year and Week Number

    I would like to display the week ending date in a Report.
    My dataset query has grouped the results by year and week number, so I am trying to construct the week ending date from year and week number.

    Week end date can be got as below
    =DateAdd(DateInterval.WeekOfYear,CInt(Fields!WeekNumber.Value) -1,DateAdd(DateInterval.Year,(Cint(Fields!Year.Value) - 1900),CInt("12/31/1899")))
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Power pivot : Can we include week level data filter in timeline?

    Can we include week level data in timeline? the Timeline object takes the date and show always the same 4
    levels(Year, Quarter, Month, Date). What if I want to filter on a week
    level ?
    thanks

    If a week selection is an immediate requirement for you, you could introduce a week name column in your calendar table (YYYY WK ww) and create a slicer based on that.
    All of the built-in time intelligence in DAX and Tabular is week-agnostic in part due to the myriad rules for handling partial weeks at year-end, and year-beginning and in part due to different week-ending days in use. If this reasoning is followed, then
    it may be unlikely that we see a week selection in a timeline.

  • Group data by week of data filter in ssrs

    Hii all
    I am creating matrix report  where report has date parameters like @From_Date and @To_Date
    and more, i want to provide a filter like selection : where user will select Weekly, Mothly or Daily
    I would do it with grouping based expreession on primary group of report ,
    when user select daily , i just group on my date field when user select yearly i have  puted a expression to format a date to year but i dont know how to do it for weeks
    well i want like Week1 , Week2 , week3 and Week 4 or (Week 5 if) week wise data 
    Help would be appreciated !
    Dilip Patil..

    Hi Dilip Patil,
    According to your description, you want to group the data based on the parameter selection. Right?
    In this scenario, it seems you only have a date column. We can use datepart() function to get the Year, Month, Week, Day from the date column. Then use the Switch() function in Group Expression to have the records group on the parameter selection. Please refer
    to the Group Expression below:
    =Switch(Parameter!param="day",DatePart(DateInterval.Day,Fields!DateCol.Value),
    Parameter!param="week",DatePart(DateInterval.WeekOfYear,Fields!DateCol.Value),
    Parameter!param="month",DatePart(DateInterval.Month,Fields!DateCol.Value),
    Parameter!param="year",DatePart(DateInterval.Year,Fields!DateCol.Value))
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • PDF form Week ending date auto populate

    i have a pdf form i am doing. it has a java script to make the week ending date populate other fields and minus a day.
    if (WEEK_ENDING.rawValue == null)
    {$.rawValue = "";}
    else
    {Num2Date(Date2Num(WEEK_ENDING.formattedValue, DateFmt(1)) - 0, DateFmt(1));}
    endif
    this works for the first date, but when i change it to
    if (WEEK_ENDING.rawValue == null)
    {$.rawValue = "";}
    else
    {Num2Date(Date2Num(WEEK_ENDING.formattedValue, DateFmt(1)) - 1, DateFmt(1));}
    endif
    it does not work. any idea what i am doing wrong?
    Tina

    Hi Tina,
    Well at first look, seems like you mixed FormCalc and JavaScript together...
    Num2Date and Date2Num can only be used in FormCalc, and you can't use these { } in FormCalc
    You should be using the if (), then, else, elseif, endif for FormCalc
    if (WEEK_ENDING.rawValue == null) then
         $.rawValue = ""
    else
         Num2Date(Date2Num(WEEK_ENDING.formattedValue, DateFmt(1)) - 1, DateFmt(1))
         or
         Num2Date(Date2Num(DateTimeField1.rawValue, "YYYY-MM-DD") + 1, DateFmt(1))
    endif

  • Week end Date Query...

    Hi
    I want Week end date for the following Condition.
    1.If month start date from sunday or monday mean week end should be Current Sat date other wise i want next saturday as first week end date.
    For Eg.. AUG 2006
    O/P should be
    12-aug-2006
    19-aug-2006
    26-aug-2006
    31-aug-2006
    2.If Months Starts from sun or monday mean i don't want last sat in the list
    For Eg.. JAN 2006
    07-jan-2006
    14-jan-2006
    21-jan-2006
    31-jan-2006
    Hlp me
    Regards
    Manikandan

    Hi jeneesh,
    Thanks for giving the query ... For the Below Same query i need
    1.If the first week of the month is Sunday Or Monday then week1 ends on the first saturday else week1 ends on the second saturday of the month.
    2. Week 2 ends on the next Saturday ( next to the one identified above)
    3. Week3 ends on the next Saturday ( next to the one indentified in step 2)
    4. Week4 ends on the last day of the Month.
    For Eg of JAN-2006, i don't want to display last sat.. insteed of i want to display last day of the month ,
    SELECT NEXT_DAY(TO_DATE('JAN-2006','mon-yyyy')+5+(N-1)*7,'SATURDAY') col1
    FROM (SELECT ROWNUM N
    FROM DUAL
    CONNECT BY LEVEL <= 4)
    WHERE NEXT_DAY(TO_DATE('JAN-2006','mon-yyyy')+5+(N-1)*7,'SATURDAY') <= LAST_DAY(TO_DATE('JAN-2006','mon-yyyy'))

  • Grouping Via Week Ending Date

    Hi All,
    I have transaction line data for each day for our customer and i would like to group via Week Ending date.  Our week runs from Sunday to Saturday.
    If i Add the transaction date to the group expert it allows me to group via week(perfect) but does it via week commencing.  I see you can group via formula, does any one know how you can get the grouping via Week Ending.
    thanks for any help and advise.
    mike

    Try using this formula...
    DateAdd("ww", DateDiff("ww", #1/6/1900#, {TableName.DateField}), #1/6/1900#)
    This formula will calculate the "Following Saturday" for any given date. If the date supplied is a Saturday, it will return that same date.
    So...
    11/2/2010 &gt; 11/6/2010
    11/13/2010 &gt; 11/13/2010
    11/14/2010 &gt; 11/20/2010
    HTH,
    Jason

  • Week Ending Date Calculation

    Hi -
    I need to calculate weekending in OBIEE Answers.
    The week will start with Sunday and end with Saturday. The week ending date for this week should be Friday of this week.
    for example :
    7th October 2012 (Sunday) - 13th October 2012(Saturday) Week Ending date should be (12th October 2012)
    Thanks!

    user8021111 wrote:
    Hi -
    Sorry.. this doesn't solved my issue..
    for example in column A I have dates like
    Column A Column B(Should be populate the week Ending Date)
    30 SEP 2012 05 OCT 2012
    01 OCT 2012 05 OCT 2012
    02 OCT 2012 05 OCT 2012
    03 OCT 2012 05 OCT 2012
    04 OCT 2012 05 OCT 2012
    05 OCT 2012 05 OCT 2012
    06 OCT 2012 05 OCT 2012
    07 OCT 2012 12 OCT 2012
    08OCT2012 12 OCT 2012
    09 OCT 2012 12 OCT 2012
    10 OCT 2012 12 OCT 2012
    11 OCT 2012 12 OCT 2012
    12 OCT 2012 12 OCT 2012
    13 OCT 2012 12 OCT 2012
    The week ending date should be considered as friday of the week..the week will start from sat and end with sund.. this all should fall under friday of that week..
    Sorry for the inconvenience caused... Thanks again.
    Thanks,Next time give the examples the first time, it'll be easier to see. Here is the formula for column B:
    TIMESTAMPADD(SQL_TSI_DAY, DAYOFWEEK(column_A)*-1+6, column_A)

  • Week ending date after 365 days in sql

    Hi Experts,
    I need to find the week ending date after 365 days of the given week start date .
    Example : Week start date : 23-Jan -2011 (Sunday)
    Desired week end date : 28-Jan-2012 (Saturday)
    How to achive this through sql ?
    Thanks .

    Hi,
    Check below this may help you, adjust "(t.day_num+1)" as per your requirment.
    with t as
    (select decode(to_char(trunc(sysdate + 365), 'dy'),'mon',1,
                                                      'tue',2,
                                                      'wed',3,
                                                      'thu',4,
                                                      'fri',5,
                                                      'sat',6,
                                                      'sun',7) day_num
                                                      from dual
    select to_char(trunc(sysdate + 365)+ (7-(t.day_num+1)),'dd dy-mm-yyyy')   
                                                      from t ;

  • Week End Date calculates dates in table issues

    Greetings All,
    I'm working on a LiveCycle Designer ES4 document that has a Week Ending Date MM-DD-YYYY (which need to always be a Saturday) selected in a subform.
    I need this Week End Date to then calculate and display the selected Saturday and the previous days in a seperate subform with a table. The days need to display in seperate columns below the header.
    This is what I have so far:
      TopmostSubform.Page1.Requestor.WeekEndDate::exit - (FormCalc, client)
    var endDate = Date2Num($,"MM-DD-YYYY")
    var dayOfWeek = Num2Date(endDate, "E")
    if (dayOfWeek <> 7) then
       xfa.host.messageBox("Ending date must be a Saturday")
       $ = null
       xfa.host.setFocus("$")
    endif
    Page1.#subform[1].InputTable.Row1[0].Date7 = Num2Date(endDate - 0, "DD")
    Page1.#subform[1].InputTable.Row1[0].Date6 = Num2Date(endDate - 1, "DD")
    Page1.#subform[1].InputTable.Row1[0].Date5 = Num2Date(endDate - 2, "DD")
    Page1.#subform[1].InputTable.Row1[0].Date4 = Num2Date(endDate - 3, "DD")
    Page1.#subform[1].InputTable.Row1[0].Date3 = Num2Date(endDate - 4, "DD")
    Page1.#subform[1].InputTable.Row1[0].Date2 = Num2Date(endDate - 5, "DD")
    Page1.#subform[1].InputTable.Row1[0].Date1 = Num2Date(endDate - 6, "DD")
    However I keep getting an error on the WeekEndDate when selecting a Saturday.
    Does anyone have any idea what I'm doing wrong?
    Thank you for any help!
    -Michelle

    Well, I never got an answer from the forum here, but to help out others - here is what I did:
    This was all done in FormCalc.
    The object WeekEndDate Date/Time Field has a set pattern date{MM/DD/YYYY} in the Object Field Pattern in LiveCycle.
    BUT, the Scripting required the pattern to be YYYY-MM-DD
    Why? I have no flipping clue. It won't work any other way for me.
    Also this item requires a Saturday Date to be chosen. Days of the week are designated by numbers (Sunday = 1, Monday = 2, etc.)
    The line <>7 means that if the day is not Saturday (7) then the error message "Ending date must be a Saturday" will appear.
    This is the Exit event Script:
    TopmostSubform.Page1.Requestor.WeekEndDate::exit- (FormCalc, client)
    var endDate = Date2Num($,"YYYY-MM-DD")
    var dayOfWeek = Num2Date(endDate, "E")
    if (dayOfWeek <> 7) then
         xfa.host.messageBox("Ending date must be a Saturday")
         $ = null
         xfa.host.setFocus("$")
    endif
    The individual Date cells are set to a Date/Time Field with no pattern set in the Object Field Pattern in LiveCycle.
    The coding below designates a MM/DD pattern.
    Each individual field has it's own scripting, with the appropriate minus calculation  - #
    This is the Calculate script for the Sunday cell:
    TopmostSubform.Page1.#subform[1].InputTable.Row1[0].Date1::calculate - (FormCalc, client)
    var dateNum = date2num(TopmostSubform.Page1.Requestor.WeekEndDate.formattedValue,"MM/DD/YYYY") - 6
    $.rawValue = num2date(dateNum,"MM/DD")
    And the Saturday cell, that needed to display the Saturday End Date has the following Script, with NO minus number:
    TopmostSubform.Page1.#subform[1].InputTable.Row1[0].Date7::calculate - (FormCalc, client)
    var dateNum = date2num(TopmostSubform.Page1.Requestor.WeekEndDate.formattedValue,"MM/DD/YYYY")
    $.rawValue = num2date(dateNum,"MM/DD")
    Why did I include this all here?
    Because this whole project has been gawd-awful, and hopefully these insights can help another struggle forms designer understand the FormCalc scripting used.
    -M

  • Week Ending Dates Logic....

    Hi All,
    I need to do a Count(measure) group by a week .
    Week is defined as should contain the "end of the each week" values.
    I tried:
    to_char(trunc(to_date(INPUT_DT,'YYYYMMDD'),'W')+7,'MM/DD/YYYY')
    but i get the wrong week ending dates? Any ideas?
    I get the values as:
    2/05/08,
    2/08/08,
    2/15/08,
    2/22/08,
    2/29/08,
    3/07/08,
    3/08/08,
    3/15/08,
    3/22/08.
    Message was edited by:
    user521009

    I need to do a Count(measure) group by a week .
    Week is defined as should contain the "end of the
    each week" values.
    Maybe this could help:
    test@ORA10G>
    test@ORA10G> -- this query displays the end date of each week in the current year
    test@ORA10G>
    test@ORA10G> select
      2    to_char(trunc(sysdate,'yyyy')+level-1,'ww') as week_number,
      3    max(trunc(sysdate,'yyyy')+level-1) as end_date
      4  from dual
      5  connect by level <= trunc(add_months(sysdate,12),'yyyy') - trunc(sysdate,'yyyy')
      6  group by to_char(trunc(sysdate,'yyyy')+level-1,'ww')
      7  order by to_number(to_char(trunc(sysdate,'yyyy')+level-1,'ww'))
      8  /
    WE END_DATE
    01 07-JAN-08
    02 14-JAN-08
    03 21-JAN-08
    04 28-JAN-08
    05 04-FEB-08
    06 11-FEB-08
    07 18-FEB-08
    08 25-FEB-08
    09 03-MAR-08
    10 10-MAR-08
    11 17-MAR-08
    12 24-MAR-08
    13 31-MAR-08
    14 07-APR-08
    15 14-APR-08
    16 21-APR-08
    17 28-APR-08
    18 05-MAY-08
    19 12-MAY-08
    20 19-MAY-08
    21 26-MAY-08
    22 02-JUN-08
    23 09-JUN-08
    24 16-JUN-08
    25 23-JUN-08
    26 30-JUN-08
    27 07-JUL-08
    28 14-JUL-08
    29 21-JUL-08
    30 28-JUL-08
    31 04-AUG-08
    32 11-AUG-08
    33 18-AUG-08
    34 25-AUG-08
    35 01-SEP-08
    36 08-SEP-08
    37 15-SEP-08
    38 22-SEP-08
    39 29-SEP-08
    40 06-OCT-08
    41 13-OCT-08
    42 20-OCT-08
    43 27-OCT-08
    44 03-NOV-08
    45 10-NOV-08
    46 17-NOV-08
    47 24-NOV-08
    48 01-DEC-08
    49 08-DEC-08
    50 15-DEC-08
    51 22-DEC-08
    52 29-DEC-08
    53 31-DEC-08
    53 rows selected.
    test@ORA10G>
    test@ORA10G>pratz

  • Week Start Date from Week Number

    How would I display the Week Start Date and Week Number for a range of dates.
    required output:
    weekno weekstartdate qty
    11 8/03/04 50
    12 15/3/04 100
    13 22/3/04 75 etc

    Do you have a start and end date and need it expanded to weeks ?
    Let's say you have a table that include both the start and end dates
    select to_char(ddate,'WW'), ddate
          from (select start_dt + rownum - 1 ddate
                  from user_objects,
                       (select min( START_DATE ) as start_dt,
                               max( END_DATE ) as end_dt
                          from MY_TABLE
                          WHERE .... )
                  where start_dt + rownum <= end_dt ) a
      where to_char(ddate,'D') = '1'
    /Of course, one of the problems with WEEK is interpretation. Week one does not start until the First Sunday of the year. Which may or may not be what you want

  • Last 5 week's datas

    Hi
    I have a period table with the below columns
    date
    week_num
    Week_desc(like week starting date to Ending date)
    Also I have a transaction table with all the datas and the date column.
    I must display the last 5 week's datas to the user along with the week_desc.
    At present Im jus hard coding the condition week_num between 13 and 17.
    can any one pls help how to achieve this without hard coding?

    Hi,
    Maybe you could try this Oracle By Example;
    http://www.oracle.com/technology/obe/obe_bi/bi_ee_1013/bi_admin/biadmin.html#t7
    Another great source although it's not a step by step explanation. Check Venat's blog;
    http://oraclebizint.wordpress.com/2007/11/14/oracle-bi-ee-101332-accessing-presentation-repository-and-session-variables-from-presentation-layer/
    Good Luck,
    Daan Bakboord

Maybe you are looking for

  • IPhone on current ios but wont let me restore without downloading latest ios (again)?

    I have an iPhone 5s running ios 7.1.1 I've connected my iphone to my itunes (on a macbook pro 2011 latest edition) and am trying to restore my iPhone. When I click on the restore button, it contacts the apple servers and then immediately directs me t

  • Accessing Var from main Nib/Class - [global variables]

    I'm sure this is a simple solution and the problem is I'm just not thinking right. I just started programming in Objective C but have come a long way in the past 2 weeks. Pretty extensive knowledge in C# and some java. Anyways, I've been creating an

  • Master Data attributes failed in Process chain

    Hi All, Master data load has failed at vendor attributes DELTA load, and error message is "'Update mode R is not supported by the extraction API". Actually in the last PC delta run it was failed at same vendor attributes delta run, due to special cha

  • Archiving old mail - as mail is running very slow

    Can someone please give me some guidance as to how to archive my older emails in Mail? I have to keep a copy of everything but some of my inbox's have 20,000+ emails in them and this is making Mail run very slow. I would love to be able to select for

  • Need more disk space - Suggestions?

    I am running out of disk space on my 20" 2GHz Intel iMac. I'm thinking upgrading the internal disk will result in much better performance than adding an external drive (I currently have an external drive used only for Time Machine). What advice do yo