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

Similar Messages

  • 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

  • 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

  • Best way to derive a "week ending" date using the Derived Column Transformations

    Hi, I have an interesting challenge. I am working on creating a BI DB that contains timesheet data. The data contains a column representing the date "worked"  ([Date]. Nearly all output reporting is based on a timesheeting week that end on
    a Wednesday. My thinking has been to create a derived column "WE" (week ending) that represents the entries of the preceding 6 days.
    (Originally I entertained deriving this value view SQL view - however we are talking about a DB that is is a substantial DB (excess of 100M timesheet bookings) and an index on the WE field is warranted) so decided a derived WE column was best approach.
    The Date field is represented from a SAP format (German long dated format) - however I cannot use the convert option ;( in the TE.
    The Date field is derived via: (DT_DATE)(SUBSTRING([Date      ],7,4) + "-" + SUBSTRING([Date      ],4,2) + "-" + SUBSTRING([Date      ],1,2))
    I would welcome some recommendation on how to best derive a WE column. (The DT_DATE format is not susceptible to a /7, mod7 operation).
    Thanks in advance,
    /L

    Try this solution :
    http://stackoverflow.com/questions/1803987/how-do-i-exclude-weekend-days-in-a-sql-server-query

  • FM to find week start and end date on the basis of a given date

    Hi Everyone,
    I have a requirement in which I require the week start and end date  of any given date.
    For eg: The given date is Wednesday 24.03.2010, I need a function module to calculate the week start date ie. Monday 22.03.2010 and week end date ie. Sunday 28.03.2010 on the basis of that date.
    Any input to this query would be helpful.
    Thanks,
    Nimisha Agarwal
    Edited by: Nimisha Agarwal on Jul 7, 2010 7:47 AM

    HI nimisha,
    many posts r there for this .
    Kindly check  before posting
    anyways this FM will serve u  r purpose.
    GET_WEEK_INFO_BASED_ON_DATE

  • Need a Help in finding the start Date and End Date of a week

    Dear All,
    I need a help,
    I have a date for eg,05-08-2009 (Wednesday). i need to get the week's start date and week's end date.
    Week start date in my region is SATURDAY and week end date is FRIDAY .
    So for my given input it should return start date as 01-08-2009 (Saturday )and end date as 07-08-2009 (Friday ).
    Thanks,

    Got it, Solved by making a small changes to the above code .
                    SimpleDateFormat sf = new SimpleDateFormat("dd-MMM-yy");
              Calendar cal = Calendar.getInstance(Locale.ENGLISH);
              cal.set(Calendar.DATE, cal.get(GregorianCalendar.DATE));
              cal.set(Calendar.MONTH, cal.get(GregorianCalendar.MONTH));
              cal.set(Calendar.YEAR, cal.get(GregorianCalendar.YEAR));
              if(cal.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) {
                cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK));
              String NewEndDate = sf.format(cal.getTime());
              cal.add(Calendar.DATE, -7);
              String newStartDate = sf.format(cal.getTime());
              System.out.println("New Start date :" +newStartDate);
              System.out.println("New End Date   :" +NewEndDate);Sorry, Dont want to hire any one . Just want to keep my job safe . Any way thanks for your reply .

  • 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

  • Forms - "Weekend Ending Date" used to Poplulate Date Fields

    Hello,
    This is my first topic, so my apologies if it is then wrong place...
    Quick question (using Acrobat 9.0 CS4 Pro Ext.),
    I am trying to set up a form where I input the week ending date (xx-xx-xx) into field "date_1"
    Once the week-ending date is input into "date_1", I would like the following fields to populate with the dates from the prior week (Monday-Sunday) "date_2", "date_3", "date_4", "date_5", "date_6", "date_7", and "date_8" respectively.  Where the week-ending date, "date_1" equals the Sunday date "date_8"
    Example:
    *Input 02-21-10 into field "date_1"
    *Auto-populate the following:
    "date_2" 02-15-10
    "date_3" 02-16-10
    "date_4" 02-17-10
    "date_5" 02-18-10
    "date_6" 02-19-10
    "date_7" 02-20-10
    "date_8" 02-21-10
    Can I use any formula with some sort of "date"+1 calulation like you can in MS Excel, or must I use some sort of script?  I am not familiar with formulas or scripts in Acrobat, so any help would be appreciated.  Hope I explained sufficiently.
    Thank you all in advance!

    Anybody?

  • Start/End Date parameters that check day of week and using to set default values.

    Hi,
    I've got a report that presents data between a start and an end date.
    I want it to check if it's a monday and present data from the previous week, otherwise present data from this week.
    For the "Default" value of parameter @startdate, I've got the following expression:
    =iif(WeekdayName(DatePart("w", Today)) = "Monday",DateAdd("d",-8,Today()),DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today(),FirstDayOfWeek.Sunday), Today()))
    for @enddate I've got default value:
    =iif(WeekdayName(DatePart("w", Today)) = "Monday",DateAdd("d",-1,Today()),DATEADD("d", 7 - DATEPART(DateInterval.WeekDay, Today(),FirstDayOfWeek.Sunday), Today()))
    but it doesn't appear to be working, I've checked 
    WeekdayName(DatePart("w", Today))
    as an expression in a text box and it evaluates to Monday but my IIF statement above always uses the DATEADD line therefore not returning "Monday" as the value (even though it is).
    Is it a problem that the parameters are of Data/Time data type and I'm trying to evaluate as type text?
    Any help would be appreciated.
    Thanks :)

    StartDate
    =IIf(DateDiff(DateInterval.Day,CDate("01/01/1900"),Today) Mod 7 =0,DateAdd(DateInterval.WeekOfYear,DateDiff(DateInterval.WeekOfYear,CDate("01/01/1900"),Today)-1,CDate("01/01/1900")),DateAdd(DateInterval.WeekOfYear,DateDiff(DateInterval.WeekOfYear,CDate("01/01/1900"),Today),CDate("01/01/1900")))
    EndDate
    =IIf(DateDiff(DateInterval.Day,CDate("01/01/1900"),Today) Mod 7 =0,DateAdd(DateInterval.Day,-1,DateAdd(DateInterval.WeekOfYear,DateDiff(DateInterval.WeekOfYear,CDate("01/01/1900"),Today),CDate("01/01/1900"))),DateAdd(DateInterval.Day,-1,DateAdd(DateInterval.WeekOfYear,DateDiff(DateInterval.WeekOfYear,CDate("01/01/1900"),Today)+1,CDate("01/01/1900"))))
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    Hi, 
    This one works but it results to be between monday and saturday, how to make it between sunday and saturday?

  • Sched.start date not allowing on week-ends for fwd scheduling process order

    Hello Experts,
    For a process order & scheduling typr forward/in time if I take sat or sunday as a start date then if I click on schedule, system changes it to previous workin day (friday). But however if i select backward/in time scheduling type & put week ends as finish day then system does not change this date.
    How can I make system to allow schedule start date on week ends also for forward/in time scheduling type. in a factory calendor sat & sunday are holidays. while for work center, calender sat & sunday are marked as working days.
    Thanks for advance,
    Vijay.

    Hi
    it depends upon client requirement.you must have defined the holiday calender as well.if you select the public holidays in your factory calender.then system will allow you to do your daily transctions on public holidays as well and vice versa.so better go with all options selected .and plz check at your end
    plz revert back if it works
    Regards
    Anupam Sharma

Maybe you are looking for

  • Insert comment in Table cell/row

    Is it possible to enter a comment in a specific table cell? When I try it only enters a comment for the whole/entire table. Thanks.

  • Again:Ping failed: Sun Application Server 8

    Hi, My Sun application server could not start its shows this ...Ping failed.. Possible reasons include: -Port conflict -Incorrect server configuration ( domain.xml to be corrected manually ) -Corrupted Deployed application preventing the server to st

  • Paralles and the "open with" menu

    Can anyone advise me on how to remove PC applications installed in Parallel appearing in the "open with" menu within osx. With most files there is no problem, but using open with in Mail gives a list of apps and no idea which ones are OSX apps or PC

  • User Selection under Permissions

    I'm uploading a set of documents programatically to a folder (an instance of ICollection). I need to set the permissions to the folder. But before I could set the permissions, I want the user to select a bunch of users using the "User Selection Searc

  • Can't close Quicktime Windows!! CMD-W is not working

    Hi my quicktime did not close anymore..CDM-W is not working and neither can i see the red amber green icons on the top left.. there is no menu when i try to rightclick within the video. the effect is dramatic that every time i open quicktime it autom