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 ;

Similar Messages

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

  • 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

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

  • Performance Management: Changing plan end date after publishing plan.

    Dear experts,
    I want to change my plan end date after publishing the plan. But there is no update option when i go to HR professional > Performance Management > Performance Management Plans > Query A plan > Update.
    Kindly guide me.

    Change the End Date of Plan and Rebublish the Plan.
    Thanks

  • 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

  • In Spool Retention Period adding - "Delete After 365 Days"? Is it possible?

    Team,
    rel 4.7
    I have the following retention periods in the spool drop down:
    Delete After 1 Days
    Delete After 2 Days
    Delete After 3 Days
    Delete After 8 Days
    Do Not Delete
    Question: I want to add other periods like 365...
    where can I maintain it.
    Thanks
    Naved
    PS. These retention periods carry over to SAPinBOX and populate expiration date field
    Message was edited by: SAPna2000
    Message was edited by: SAPna2000

    Hi,
    I know Job retention period by using T/code : SO16--> document org.
    Check this may help.
    Lanka

  • Extend End date after the end date has reached

    Hi gurus,
        We are using SRM5.0 on ECS with backend ECC5.0.
        We notice that after the end date of bid has reached even though there is a bid submitted by supplier , the purchaser still can extend the end date to a later date as long as he has not made the accept or reject choice.
        If it is the case, the purchaser can view the price after the end date reached and then extend the end date and maybe tell other supplier what the price the opponent has submitted. This is not allowed and should be penaltied.
        We just want to know how to avoid this in the term of system. Can we make the
    end date field unchangeable after the end date has reached? or any other solutions?
    Thank you in advance.
    Message was edited by:
            YE Wang

    Hi,
    As Teja and SAndeep mentioned,you can go for either the Approval or BADI approach.
    In case you are implementing the BADI,you can make the concerned fields grayed out so no changes are made but then this would mean that <b>no changes
    </b> can be done at all after the END date has been reached.
    In case of workflow,you can have you starting conditions in which you will compare the end date and the system date .If same,you can trigger  a Workflow for approval of any changes to be done further.So even if the changes are made,the chnages are approved by a higher authority.
    Another way would be to implement the "BBP_DOC_CHECK_BADI" to check whether the end date has been reached and then allow the user to do any changes.You can use the FM "BBP_PD_BID_GETDETAIL" to get the details of the BI and then check.In this case,you can additionally check for other parameters of the User like role,authorisation based on which he can make changes in exceptional cases.
    BR,
    Disha.
    <b>Pls reward points for useful answers.</b>

  • Calendar app changes End date of all-day events? Grrrr.

    Okay this is getting incredibly frustrating. I use all-day events essentially as to-Do's. Things I have to do on a given day but no assigned time to do them.
    (I can't stand the idea of a separate to do list from my calendar so don't bother suggesting that please)
    If I do the task, I simply delete the to-do (I.e. I delete the all-day event).
    If I am unable to do it on the given date, I move it to a later date. Sometimes the best day, sometimes a few days later.
    Here is what happens...
    - I select the event
    - I hit Edit
    - I hit the Start/End date, up comes the date scroll wheel
    - I change the start date, which also changes the end date to match, then hit Done
    - when I am back to the event listing, the end date has CHANGED.  Sometimes it's a day later, sometimes several. No rhyme or reason or pattern I can discern.
    Help as this is really annoying.
    This was happening on my iPad 2 and is now happening on my New iPad.

    Nope.  In fact, not only have I not fixed it, I now also have a new problem with iCal events - both timed and all day.
    Some, for no rhyme or reason, add an alert. They always seem to be the day before at 9am alerts.
    If I go into the event and remove the alert, it will often recreate the alert a few days later.
    VERY FRUSTRATING!!

  • Very Strange- Mail changes all dates after two days

    I have a very strange behavior:
    Apple Mail changes the date-information of incoming and outgoing mails after about two days -
    for the first two days it says "today" or "yesterday" after that it changes all dates to one single date (december 12.2009 and some to december 12.2010).
    I just put in a new pram battery, so this cannot be the problem.
    what the heck is this?

    Hi Noe, do you have anything in Rules that is set to happen after 2 days?
    Not certain, but this can fix myriad Mail problems...
    Safe Boot from the HD, (holding Shift key down at bootup), it will try to repair your Disk Directory while the spinning radian is happening, so let it go, run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions, then move these folder & file to the Desktop.
    Move this Folder to the Desktop...
    /Users/YourUserName/Library/Caches/Mail/
    Move this file to the Desktop...
    /Users/YourUserName/Library/Mail/Envelope Index
    Reboot.
    If that doesn't do it and you can afford to redo all your Rules, try these & reboot...
    /Users/YourUserName/Library/Mail/MessageRules.plist
    /Users/YourUserName/Library/Mail/MessageRules.plist.backup

  • To get first date and end date after entering any month and year

    Hi,
    I need to to get first date and end date of a month and year in yyyyMMdd format. I am reading month and year from a properties file. But I don't know how to get the first date and End date in given format. The properties file gives me just text. But I don't know how to get the date format using this. I need this urgently. Can anyone help me to get code for this?
    I am reading the fields as,
    Properties props = new Properties();
    props.load(new FileInputStream("AnyMonthVolume.properties"));
    String date_month = props.getProperty("date_month");
    String date_year = props.getProperty("date_year");
    Thanks.

    I know this has been posted a while ago but incase someone looking for it, here is the code to get the end of current month date.
    Calendar cal = Calendar.getInstance();
         cal.setTime(new java.util.Date());
         cal.set(Calendar.DATE, 1); //set the date to start of month
         cal.add(Calendar.MONTH,1);
         cal.add(Calendar.DATE,-1);
    System.out.println(cal.getTime());

Maybe you are looking for

  • Journal Voucher Print Layout

    Hi, Is there any way to customize the print layout of a journal voucher to include more columns such as user defined fields that may be present in the journal voucher Entry rows? thanks, Costas

  • No GUI after reboot for Oracle Linux 6 installation

    I am trying to resolve an Oracle Linux 6.2 (64 bit) installation issue. I selected Oracle Linux server default setup and after the reboot, the X-Window or KDE GUI graphical interface does not come up. Instead, I get a command line prompt. Any idea ho

  • My brother bought two apps that costed money ( he thought they were games I cancelled the download and my money is gone help

    I really need help my little brother (3) bought and app because he thought they were 1$ games but ended up to be photo editing apps I tried to stop the last on but they still took off my credit money

  • Cannot run Crystal report in SAP

    Dear all, I install the crystal report add-on and upload a report. I also installed CRRuntime_12_1_mlb.exe When I preview the report, I got this error message Could not load file or assembly 'CrystalDecisions.Windows.Forms, version=12.0.2000.0, cultu

  • Deploy additional files

    Hi, I need to use Axis Framework and follow this guide http://help.sap.com/saphelp_nw04/helpdata/en/45/a4f8bbdfdc0d36e10000000a114a6b/content.htm How to compress .jar files into .sda. Where should I deploy it? Is that possible to copy the .jar files