Previous Saturday's date

I need to write a function that will return the previous Saturday's date from a date passed into the function.
On a similar note I need to be able to get Friday's date of 4 weeks from a specific date passed into the function.
Thank you in advance for answering this post and any help will be appreciated.
Thanks
Adam

"APCs solution has the drawback that you need to provide the weekday in the date language of your session"
An easy workaround if you don't know the date language for the session:
last Saturday
SQL> SELECT NEXT_DAY(sysdate-7, TO_CHAR(TO_DATE('03-jan-1970','dd-mon-yyyy', 'nls_date_language = ENGLISH'), 'DAY'))
  2  FROM dual;
NEXT_DAY(
22-APR-06Friday 4 weeks off:
SQL> SELECT NEXT_DAY(sysdate+28, TO_CHAR(TO_DATE('02-jan-1970','dd-mon-yyyy', 'nls_date_language = ENGLISH'), 'DAY'))
  2  FROM dual;
NEXT_DAY(
26-MAY-06Just pick a date you know is the correct day of the week.
SQL> ALTER SESSION SET nls_date_language = 'FRENCH';
Session altered.
SQL> SELECT NEXT_DAY(sysdate-7, TO_CHAR(TO_DATE('03-jan-1970','dd-mon-yyyy', 'nls_date_language = ENGLISH'), 'DAY'))
  2  from dual;
NEXT_DAY(
22-AVR-06Voila, language independent.
The nls_date_language parameter is required in the TO_DATE to avoid
SELECT TO_DATE('22-apr-2006','dd-mon-yyyy') from dual;
SELECT TO_DATE('22-apr-2006','dd-mon-yyyy') from dual
ERROR at line 1:
ORA-01843: not a valid monthWhen the date language is different.
TTFN
John

Similar Messages

  • Get the previous Saturday

    Hi,
    I have a fcn which gest the current date as follows
    public String getDate() {
              Calendar cal = new GregorianCalendar();
              int year = cal.get(Calendar.YEAR);
              int month = cal.get(Calendar.MONTH) + 1;
              int day = cal.get(Calendar.DAY_OF_MONTH);
              return month+"/"+day+"/"+year;
    Now i want to create a nother fch which uses getDate to get the date of the previous saturday. Is this possible?
    Thanks,
    Mike

    First comment - it's better to use java.text.DateFormat to format dates, that's what it's for.
    Something like this ought to work:
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_YEAR,
    -((cal.get(Calendar.DAY_OF_WEEK) - Calendar.SATURDAY) % 7));

  • Recently purchased a used IPad 2 but it still has previous owner's data.  I've been told not to sync it to my computer as it will cause problems.  What do I need to do to make it compatible with accounts on my mac and ipod touch?

    Recently purchased a used IPad 2 but it still has previous owner's data.  I've been told not to sync it to my computer as it will cause problems.  What do I need to do to make it compatible with accounts on my mac and ipod touch?  Thanks for any and all help!

    You can wipe the iPad's contents completely by going to Settings>General>Reset>Erase All Content and Settings. This will remove all of the previous user's apps, data, settings and so on from the iPad and you can set it up as your own.

  • Inclusion of line items before previous document due date passed

    Hi All,
    I am having below mentioned scenario:
    1. I am invoicing a consumer in Aug-14 with periodic billing order. Document is having due date of 10-Sep.
    2. Further I am doing interim billing and invoicing (before previous document due date expired) with posting date say 05-Sep.
    The recent document of 05-Sep is not including all line items of document invoiced in Aug-14.
    How do we include Aug-14 bill line items in next invoicing.
    Saurabh

    Hi,
    If you are not using Integrated Account Maintenance, under "Item Selection for Bill printout (Subitems)" it should be as easy as leaving Open Items Selection restriction blank - meaning "All open items for contract acct (w. and w/o ref. to cntrct)", setting the "Interval days for the due date of items to be printed" to 999, and choosing the "Consider Items in Bill Sum Total" setting - once or always, I believe. If it doesn't work, I'd be looking at FQEVENT R410 FMs to see if the Items are passed that far.
    <rant on>I can't to this day get how come so many Utilities (in my experience - all I've worked with) practice this "double" or even multiple billing of the same amounts (even if the amounts do not multiply in FI-CA postings, you have invoiced the amounts to customer multiple times). Or rather - nobody has been able to tell a valid and irrefutable reason, why things need to be done that way - it's usually "that's how we have always done it" reason. The accounting people don't even care that the previous invoice remains valid in the system (as long as their precious FI-CA postings do not multiply), because there is nothing in IS-U that automatically reverses or invalidates it... And I don't get why the regulators even permit it...<rant off>
    cheers
    Jānis

  • Displaying current and previous 5 Year data in a bar graph

    Hi ,
    My requirement goes like this .....
    I have to show revenue (measure) data based on current year (period dimension) selection (from a dashboard prompt) and previous 5 year data's as well .
    i.e. if user selects 2013 , the bar graph will display 6 bars ... 2013,2012,2011,2010,2009,2008.
    I am trying to achive this with filter on Year column , on the main report ....*"is based on results of another analysis"*
    But haven't made any progress .
    Thanks
    sayak

    sayak wrote:
    Hi ,
    My requirement goes like this .....
    I have to show revenue (measure) data based on current year (period dimension) selection (from a dashboard prompt) and previous 5 year data's as well .
    i.e. if user selects 2013 , the bar graph will display 6 bars ... 2013,2012,2011,2010,2009,2008.
    I am trying to achive this with filter on Year column , on the main report ....*"is based on results of another analysis"*
    But haven't made any progress .
    Thanks
    sayakFollow this link. It will give you greater flexibility for you end users and therefore a better report.
    http://oraclebizint.wordpress.com/2008/03/11/oracle-bi-ee-101332-rolling-yearmonth-and-date-filters-moving-window-filters/

  • Previous month first data and previous month last date

    can any body have query to get previous month first date and previous month last date.
    Ex: First day of the previous week:
    TIMESTAMPADD(SQL_TSI_DAY,-6, (TIMESTAMPADD(SQL_TSI_DAY, DAYOFWEEK(CURRENT_DATE) *-1,CURRENT_DATE)))
    Last day of the previous week:
    TIMESTAMPADD(SQL_TSI_DAY, DAYOFWEEK(CURRENT_DATE) *-1,CURRENT_DATE)
    can anybody have it for first day of the previous month,last day of the previous month?
    Edited by: user12255470 on Apr 7, 2010 3:30 AM

    Hi,
    1st day of previous month :
    TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE)) * -1) + 1, TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE))
    last day of previous month :
    TIMESTAMPADD(SQL_TSI_DAY,DAYOFMONTH(TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE)) * -1 , TIMESTAMPADD(SQL_TSI_MONTH, 1, TIMESTAMPADD(SQL_TSI_MONTH,-1,CURRENT_DATE)))
    Please mark Q answered and award points for correct answers !
    Thanks
    Alastair

  • Safari storing previous secure session data in plain text.

    I was just forwarded a link stating that Safari stores previous secure session data unencrypted in a hiodden folder. The article said this applies to OS X 10.8.5,and OS X 10.7.5 running Safari 6.0.5. Has this vulnerability been fixed in Mavericks/Safari 7.0?
    http://securityaffairs.co/wordpress/20482/hacking/safari-unsecure-data-storage.h tml

    It's not the transit that I'm asking about, but a secure local session with private info in a hidden folder. If another user gains access to this hidden folder, then private info can be disclosed (i.e., passwords, address).

  • HT1386 Since 8th May , I am not able to synchronize my iPhone with iTunes. Have tried removing previous back up data , removed all photos and videos on iPhone , switched  on and of and  reset iPhone  a million times , restarted my Mac a thousand times :(

    Since 8th May , after updating the iphone software to 5.1.1  I am not able to synchronize my iPhone with iTunes. Have tried removing previous back up datas , removed all photos and videos on iPhone , switched  on and of and  reset iPhone  a million times , restarted my Mac a thousand times Please Help !!!

    I have tried both options .. back up on this computer and also back up on icloud.
    The backingup is fine .. there is no problem .. even synchronizing songs , applications , calender , mail accounts is fine .. only the contacs are not synchronizing. The itune goes on and on .. showing synchronizing contacs .. but nothing happens. When i uncheck contacts synchronisation .. everything works fine . I have also reorganized my address book . but it does not help

  • Previous month last date in sql

    hi
    i am using function
    select dateadd(day,1 - DATEPART(day,dateadd(month,24-36,GETDATE())),dateadd(month, 24- 36, getdate()))
    this will giveme 2014-03-01,
    now what changes  i need to make this function which will give me previous month last date.
    2014-02-28

    Hi coool_sweet,
    The answers in above posts are excellent. In case you may need any tip for date calculation, here is a good link for your reference.
    Date and Time Data Types and Functions - SQL Server (2000, 2005, 2008, 2008 R2, 2012)
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Refer to previous row's data

    Is it possible to refer to a previous row's data inside
    spry:if? Something like spry:if=" '{sampleDS::ds_RowID[this -
    1]::category/@name}'= '{sampleDS::category/@name}' "
    Right now I have to store the part I want compared in a JS
    variable.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml"
    xmlns:spry="
    http://ns.adobe.com/spry">
    <head>
    <title>Sample</title>
    <script type="text/javascript" language="javascript"
    src="scripts/SpryData.js"></script>
    <script type="text/javascript" language="javascript"
    src="scripts/xpath.js"></script>
    <script type="text/javascript" language="javascript">
    <!--
    var sampleDS = new Spry.Data.XMLDataSet("sample.xml",
    "/programs/program", {sortOnLoad: ['category/@name', 'title']});
    sampleDS.loadData();
    var prevCat = new String;
    var thisCat = new String;
    -->
    </script>
    </head>
    <body>
    <div spry:region="sampleDS">
    <div spry:repeat="sampleDS">
    <h1 spry:if="prevCat = thisCat; thisCat =
    '{sampleDS::category/@name}'; thisCat != prevCat"
    >{sampleDS::category/@name}</h1>
    <h2>{sampleDS::title}</h2>
    </div>
    </div>
    </body>
    </html>
    sample.xml:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <programs>
    <program id="5">
    <category id="2" name="Category 2" />
    <title>Program E</title>
    </program>
    <program id="2">
    <category id="1" name="Category 1" />
    <title>Program B</title>
    </program>
    <program id="4">
    <category id="1" name="Category 1" />
    <title>Program D</title>
    </program>
    <program id="3">
    <category id="1" name="Category 1" />
    <title>Program C</title>
    </program>
    <program id="1">
    <category id="2" name="Category 2" />
    <title>Program A</title>
    </program>
    </programs>
    Thanks,
    Andrew

    Thanks, that's a lot cleaner than what I had.
    var sampleDS = new Spry.Data.XMLDataSet("sample.xml",
    "/programs/program", {sortOnLoad: ['category/@name', 'title']});
    var categoryDS = new Spry.Data.XMLDataSet("sample.xml",
    "/programs/program/category", {distinctOnLoad: true, sortOnLoad:
    '@name'});
    sampleDS.loadData();
    <div spry:region="sampleDS categoryDS">
    <div spry:repeat="categoryDS">
    <h1>{categoryDS::@name}</h1>
    <h2 spry:repeat="sampleDS"
    spry:test="'{categoryDS::@name}' ==
    '{sampleDS::category/@name}'">{sampleDS::title}</h2>
    </div>
    </div>

  • YTD and and previous year to date as variables

    HI All,
    If your cube doesn't have YTD and and previous year to date as variables to use - can these be created?
    Regards J

    Hi,
    Yes it can be staged in cube but you need to write routine and transformation/update rule level.
    If you need for some query requirement then you may achieve the same at query level. For this you need to create some Restricted Key figures by restricting your key figure with Calyear/month as per your need.
    Query level approcah will be much easier then the cube level.
    I hope it will help.
    Thanks,
    S

  • Previous month end date

    hello,
    i would like to find out the previous month end date when i give the input any date .
    finding previous month end date.
    eg :-> if i give the date as 02-Jan-2008, the result should be 31-dec-2007
    if i give the input date as 10-nov-2007, the previous month end date is 31-Oct-2007
    etc...

    ME_XE?select the_date, trunc(the_date, 'MM') - 1 as las_day_prev_month
      2  from
      3  (
      4     select add_months(sysdate, level) as the_date from dual connect by level <=12
      5  );
    THE_DATE                   LAS_DAY_PREV_MONTH
    02-FEB-2008 08 58:30       31-JAN-2008 12 00:00
    02-MAR-2008 08 58:30       29-FEB-2008 12 00:00
    02-APR-2008 08 58:30       31-MAR-2008 12 00:00
    02-MAY-2008 08 58:30       30-APR-2008 12 00:00
    02-JUN-2008 08 58:30       31-MAY-2008 12 00:00
    02-JUL-2008 08 58:30       30-JUN-2008 12 00:00
    02-AUG-2008 08 58:30       31-JUL-2008 12 00:00
    02-SEP-2008 08 58:30       31-AUG-2008 12 00:00
    02-OCT-2008 08 58:30       30-SEP-2008 12 00:00
    02-NOV-2008 08 58:30       31-OCT-2008 12 00:00
    02-DEC-2008 08 58:30       30-NOV-2008 12 00:00
    THE_DATE                   LAS_DAY_PREV_MONTH
    02-JAN-2009 08 58:30       31-DEC-2008 12 00:00
    12 rows selected.
    Elapsed: 00:00:00.12
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Previous month end data for report

    Hi expert,
    I have to calculate previous month end data for my report.
    let say if user select 15 oct then he should be able to see 30 sept data.
    I have calander prompt.
    Thanks,

    Hi,
    Use presentation variable in date prompt.
    Apply sql filter(covert to sql) on report as date_column= TIMESTAMPADD(SQL_TSI_DAY,-DAYOFMONTH(date 'presntation_variable'),date 'presentation_variable')
    Refer : How to get LAST_DAY in obiee
    Regards,
    Srikanth

  • FOX to read previous month's data

    Hi Guys, i have the following FOX to calculate LINE '57' but cannot read previous month's data.
    please assist.
    DATA LINE TYPE ZBPLINE.
    DATA FISCPER TYPE 0FISCPER3.
    DATA PREV_MONTH TYPE 0FISCPER3.
    DO.
    PREV_MONTH = TMVL (FISCPER , -1) .
    {0BALANCE,FISCPER ,57} = {0BALANCE,PREV_MONTH,57} + {0BALANCE,FISCPER,12}.
    FISCPER  = TMVL(FISCPER , 1).
    IF FISCPER  > PREV_MONTH.
    EXIT.
    ENDIF.
    ENDDO.

    Lerato,
    I am not sure how is your data model, but here are a couple tips
    DATA LINE TYPE ZBPLINE.
    DATA FISCPER TYPE 0FISCPER3. ->>>>>  This sHould probably be 0FISCPER
    DATA PREV_MONTH TYPE 0FISCPER3. ->>>>>  This should probably be 0FISCPER
    data finalmonth type 0FISCPER3. ** or 0fiscper!
    finalmonth = TMVL(FISCPER , 12).
    *initialize you fiscper
    fiscper = '201001'. * or call a variable
    DO.
    PREV_MONTH = TMVL (FISCPER , -1) .
    {0BALANCE,FISCPER ,57} = {0BALANCE,PREV_MONTH,57} + {0BALANCE,FISCPER,12}.
    I am not sure what is 57 and 12. Is it your planning item?
    FISCPER = TMVL(FISCPER , 1).
    This exit if statement should be like this
    if FISCPER  > finalmonth.
    EXIT.
    ENDIF.
    ENDDO.
    Hope that helps
    Alex Zetune
    goldstrategy.com

  • To get previous month's data

    Hi
    My report requirement:
    Display current month and previous month's data (sal) next to each other based on the month selected as a current month.
    Expression I'm using at the moment:
    case when trunc(lag(dt,1,dt) over (partition by ename order by dt),'MM') = trunc(add_months(dt,-1),'MM')
    then lag(sal,1,sal) over (partition by ename order by dt)
    However, instead of 'dt' I'm trying to use a parameter (dt as a current month's dt).
    This gives me an error message.
    Can anyone guide me on this?
    Thanks and regards,
    Aparna

    Why not simply join the table with itself? I.e. join the two months data sets and have a single row containing current and previous month results
    Simplistic example. We have a YEARLY_TOTALS table where the primary key is MONTH in the date format YYYY/MM. You can then compare the sales totals per month of this year with that of last year using the following type of SELECT construct:
    SELECT
    cur.month,
    cur.sales as CURRENT_SALES,
    prev.sales as LAST_YEAR_SALES
    FROM yearly_totals cur
    JOIN yearly_totals prev
    ON ADD_MONTHS(prev.month,12) = cur.month
    WHERE cur.month >= TRUNC(SYSDATE,'YY')

Maybe you are looking for