Month Between Fn

Hi All,
I am using OBIEE 10g.I have time dim and Product fact table.
My requirment is
Prompt
Year;Month;month(Duration)
Above prompt says Year like 2010,2011,2012
Month:1,2,3,4,5,6,7,8,9,10,11,12
Duration: user enter values,like 2 or 3 or 4 or.....
First user selecting Year=2012 then Month=4 then Duration=4 (duration 4 means month of Apr-2012 into Aug-2012--added 4 month from user selection month)
Then i created one report based on measure values.In that report i set year is prompt and month also is prompt.
After How can Set duration filter?My requirment is when user selecting duration=4 then report should be display based on Month and Duration values
My report should be below
Year,Month,Amount
2012,4,1000
2012,5,2000
2012,6.2000
2012,7.3000
Only problem How to implement DURATION filter
Thanks
GRam.

Hi,
Capture Month in a presentation variable say Pv_Month and duration in another presentation variable Pv_Duration
then filter the report as
Month is greater than or equal to @{Pv_Month}{1}
Month is less than equal to (@{Pv_Month}{1} + @{Pv_Duration}{4})
Thanks

Similar Messages

  • How to get LASTDAY for each and every month between given dates..

    Hi Friend,
    I have a doubt,How to get LASTDAY for each and every month between given dates..
    for ex:
    My Input will be look like this
    from date = 12-01-2011
    To date = 14-04-2011
    And i need an output like
    31-01-2011
    28-02-2011
    31-03-2011
    is there any way to achieve through sql query in oracle
    Advance thanks for all helping friends

    Here's a 8i solution :
    select add_months(
             trunc(
               to_date('12-01-2011','DD-MM-YYYY')
             ,'MM'
           , rownum ) - 1 as results
    from all_objects
    where rownum <= ( months_between( trunc(to_date('14-04-2011','DD-MM-YYYY'), 'MM'),
                                      trunc(to_date('12-01-2011','DD-MM-YYYY'), 'MM') ) );
    The above two query is worked in oracle 11GActually the first query I posted is not correct.
    It should work better with
    months_between(
       trunc(to_date(:dt_end,'DD-MM-YYYY'),'MM'),
       trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM')
    )Edited by: odie_63 on 12 janv. 2011 13:53
    Edited by: odie_63 on 12 janv. 2011 14:11

  • Need Help on List of Months between Two Dates

    Hello everyone,
    I have a table which has startdate & enddate, and need a SELECT statement to list all months between these two dates for each given ID.
    I did some test, and could not figure out how to get the startdate & enddate from testing table (instead of hard code them) in the select statement.
    Could anybody please help on it (Oracle 11gR2),
    Thanks in advance!!!
    create table testing(
    id          number,
    start_date  date,
    end_date    date);
    insert into testing values(100, to_date('05-FEB-2011', 'DD-MON-YYYY'), to_date('28-MAY-2011', 'DD-MON-YYYY'));
    insert into testing values(200, to_date('20-JUN-2011', 'DD-MON-YYYY'), to_date('28-DEC-2011', 'DD-MON-YYYY'));
    commit;
    select * from testing;
            ID START_DAT END_DATE
           100 05-FEB-11 28-MAY-11
           200 20-JUN-11 28-DEC-11
    Elapsed: 00:00:00.01
    *for testing.id = 100:*
    select to_char(add_months(to_date('05-FEB-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates
    from (select level l
           from dual
        connect by level <= months_between(trunc(to_date('28-MAY-2011', 'DD-MON-YYYY'), 'MONTH'),
                                           trunc(to_date('05-FEB-2011', 'DD-MON-YYYY'), 'MONTH')) + 1);
    DATES
    2011-Feb
    2011-Mar
    2011-Apr
    2011-May
    Elapsed: 00:00:00.01
    *for testing.id = 200:*
    select to_char(add_months(to_date('20-JUN-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates
    from (select level l
           from dual
        connect by level <= months_between(trunc(to_date('28-DEC-2011', 'DD-MON-YYYY'), 'MONTH'),
                                           trunc(to_date('20-JUN-2011', 'DD-MON-YYYY'), 'MONTH')) + 1);
    DATES
    2011-Jun
    2011-Jul
    2011-Aug
    2011-Sep
    2011-Oct
    2011-Nov
    2011-Dec
    7 rows selected.

    SQL> select * from testing
      2  /
            ID START_DAT END_DATE
           100 05-FEB-11 28-MAY-11
           200 20-JUN-11 28-DEC-11
    SQL> select  id,
      2          to_char(add_months(start_date,column_value - 1),'YYYY-Mon') dates
      3    from  testing,
      4          table(
      5                cast(
      6                     multiset(
      7                              select  level
      8                                from  dual
      9                                connect by add_months(trunc(start_date,'MM'),level - 1) <= end_date
    10                             )
    11                     as sys.OdciNumberList
    12                    )
    13               )
    14    order by id,
    15             column_value
    16  /
            ID DATES
           100 2011-Feb
           100 2011-Mar
           100 2011-Apr
           100 2011-May
           200 2011-Jun
           200 2011-Jul
           200 2011-Aug
           200 2011-Sep
           200 2011-Oct
           200 2011-Nov
           200 2011-Dec
    11 rows selected.
    SQL> SY.

  • List Months between a date range

    Hi, I'm trying to list the months between a given date range in an ABAP report to generate a MIS report(ALV).. Say I have 2 date ranges, 01.01.2006 to 01.04.2006.. I want to list
    Jan 2006
    Feb 2006
    Mar 2006
    Apr 2006.. Any FM in SAP to get this OP..

    hi vivek,
    use this function module to get months beween two dates
    1. MONTHS_BETWEEN_TWO_DATES   or
    2. MONTHS_BETWEEN_TWO_DATES_NEW
    please reward the point if you are satisfied with answer
    thanks,
    john.

  • Generate all Months between start and end dates using Parameter

    Hi,
    I have a query in which i have two dates that is Start Date and End Date and now i have to populates all the Months between the date range:
    Start Date : APR-12
    End Date: JUL-12
    Now taking these two values i want the recors as displayed below
    APR-12
    MAY-12
    JUN-12
    JUL-12
    So how can write my SQL query to finish this task
    Thanks

    Sounds easy with single pair of Months:
    with data(st_dt, end_dt) as
      select to_date('JAN-2012', 'MON-YYYY'), to_date('SEP-2012', 'MON-YYYY') from dual
    select add_months(st_dt, level - 1  ) mons
      from data
    connect by level <= months_between(end_dt,st_dt) + 1;
    MONS   
    01-JAN-12
    01-FEB-12
    01-MAR-12
    01-APR-12
    01-MAY-12
    01-JUN-12
    01-JUL-12
    01-AUG-12
    01-SEP-12
    9 rows selected Please ensure to read {message:id=9360002} and post the question correctly with all the mentioned points in the thread. It facilitates the people to understand the problem clearly and provide a solution that is compatible with your Oracle Version.

  • Calender:Obtaining days/weeks/months between a start & end Calendar range

    I have a startDate and endDate of Calendar type. From this start and end calendar values I want to obtain all the days/weeks/months.
    Eg
    Calendar beginDate; // is 14-Oct-2006
    Calendar endDate; // is 20-Mar-2007
    If I am looking at the months between the two calendar values, I want to be able to know that
    [1] there are 6 months
    [2] The months are Oct 2006, Nov 2006... Mar 2007 (across years i.e. 2006 and 2007 as well)
    I want to be able to have a generic solution to do this at the days and weeks level as well.
    Really appreciate all help.
    Thanks,

    I was able to come up with a solution, if any better is known, please suggest:
    Summary of what I did:
    [1] First formated the end and start Calendar dates using SimpleDateFormat, and brought it to the 'MMM yyyy' structure, so that I have a common base to compare on
    [2] depending on condition, I increment the month and copy the result into an ArrayList that I need for use later.
    Snippet of the code is here:
    SimpleDateFormat monthYear    = new SimpleDateFormat("MMM yyyy");
    ArrayList<String> MonthInDateRange = new ArrayList<String>();
    Calendar calTempDate, calStartDate, calEndDate, calCurrentDate;
    String StartDateFormat, EndDateFormat;
    TempDateFormat = StartDateFormat;
    StartDateFormat = monthYear.format(calStartDate.getTime());
    EndDateFormat = monthYear.format(calEndDate.getTime());
    MonthInDateRange.add(StartFormat); // Starting Month
    calCurrentDate = calStartDate;
    while ( !(TempDAteFormat.equalsIgnoreCase(EndDateFormat)) ) {
                calCurrentDate.add(calCurrentDate.MONTH, +1);
                TempFormat = monthYear.format(calCurrentDate.getTime());
                MonthInDateRange.add(TempFormat);   
    Would like to know whether any of you have used a function in Calendar that can help me acheive the same thing, but in a more efficient manner. As I am looking for something generic that I can use at different levels daily,weekly, monthly (currently what I solved above), etc.
    Thanks,
    Edited by: mnr on Dec 5, 2007 6:01 AM

  • Months between two date

    There two ways of finding months between two dates
    ROUND((Date1 – Date2) / 365.25 * 12,2) and
    ROUND(months_between(date1,date2),2) There is a slight difference between output from these two.
    I think the result from the second statement should be more accurate, confirm?
    Abhishek

    AbSHeik wrote:
    There two ways of finding months between two dates
    ROUND((Date1 – Date2) / 365.25 * 12,2) and
    ROUND(months_between(date1,date2),2) There is a slight difference between output from these two.
    I think the result from the second statement should be more accurate, confirm?
    AbhishekHi Abhishek,
    I also agree with this.
    Coz 365.25 = (365 + (1/4))
    This 0.25 actually the extra year of a Leap Year, distributed equally among 4 years. But, when the 1st formula is evaluated, the calculation might cause difference...
    So as far as Oracle is concerned, MONTHS_BETWEEN should be used.
    Please rectify me if i'm wrong.
    Ranit B.

  • Find the Duration in Months between the contents in an Iterator

        Iterator<String> termIncomeKeys = termIncome.keySet().iterator();
        while(termIncomeKeys.hasNext()){
            String month = termIncomeKeys.next();
            System.out.println(month);
        } The above code is printing month as
    Jan(2012) - Jan(2012)
    Feb(2012) - Mar(2012)
    Apr(2012) - May(2012)
    Jun(2012) - Jun(2012)
    Jul(2012) - Oct(2012)What I want to achieve is I want to print the duration in terms of months between each of the entries. That is, Duration between first entry is 1 month, duration between second is 2 and so on.

    What you print is a string. You can't do calculations on a string. You have first to disassemble the string into parts and interpret what each part contains. There is nothing out of the box in java to do this. On the other side it's not too difficult to do it yourself.
    Timo

  • Months between Dates

    Hi All,
    How do i get the number of months between 2 dates ?
    I have the 2 dates stored as
    Date EffctFrmDt = voRow.getEffectiveFromDate();
    Date EffctToDt = voRow.getEffectiveToDate();
    The values printed for EffctFrmDt & EffctToDt are 2008-06-11 & 2008-10-31
    I'm trying to print the months
    System.out.println("Date diff : " + EffctFrmDt.diffInMonths(EffctToDt));
    I get the following Error stack
    oracle.apps.fnd.framework.OAException: oracle.jbo.domain.GenericDomainException: JBO-25023: Error while performing operation:Date.diffInMonths on domain value:2008-06-11 of class:oracle.jbo.domain.Date.
    at oracle.apps.fnd.framework.OAException.wrapperException(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at OA.jspService(_OA.java:71)
    at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    ## Detail 0 ##
    java.sql.SQLException: Unimplemented method called
    at oracle.sql.LdxLibThin.ldxsbm(LdxLibThin.java:1402)
    at oracle.sql.DATE.diffInMonths(DATE.java:918)
    at oracle.jbo.domain.Date.diffInMonths(Date.java:507)
    at agi.oracle.apps.cn.quota.webui.CustomSnltyCreatePgCO.processFormRequest(CustomSnltyCreatePgCO.java:281)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at OA.jspService(_OA.java:71)
    at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    java.sql.SQLException: Unimplemented method called
    at oracle.sql.LdxLibThin.ldxsbm(LdxLibThin.java:1402)
    at oracle.sql.DATE.diffInMonths(DATE.java:918)
    at oracle.jbo.domain.Date.diffInMonths(Date.java:507)
    at agi.oracle.apps.cn.quota.webui.CustomSnltyCreatePgCO.processFormRequest(CustomSnltyCreatePgCO.java:281)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.beans.OABodyBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.processFormRequest(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
    at OA.jspService(_OA.java:71)
    at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
    at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
    at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:221)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:122)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:111)
    at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
    at java.lang.Thread.run(Thread.java:595)
    Am I doing anything wrong or is there some other approach to this ??
    Thanks and Regards,
    Dean

    There can be two possible approcahes:
    JAVA
    Use calendar class, its pretty straight forward.
    sql
    SELECT MONTHS_BETWEEN('01-JAN-01','01-AUG-01') AS MONTHS_BETWEEN FROM Dual;
    Please do a google before basic threads for core java.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to Calculacte No of Months between 2 give dates at Report Leve

    Hi Experts,
      I had 2 Key Figures of DATs Format...
      I can i calculacte No of Months between 2 given dates at Bex Query Designer Level
    I am intrested in Calculacting exact months...not No of Days
    Please advise

    Try creating 2 replacement variables of number format to include only the month and then use a formula to get the difference between the var 1 and var 2.
    Hope this helps.
    Best Regards,
    Hima

  • How to Calculate number of months between two dates

    Hi All,
       In one of the fomr developments, I have to calculate the
    Number of Days
    Number of Months ( Considering Leap Year) provided by the dates, end user enters in the form,
    After going thorugh some forum discussion, I have come to know about so many things which were not clear till now.
    I have gone through various forums too,  some one suggets to make use of FORM CALC and some other JAVA SCRIPT. But the logic i want to build in java script.
    The most interesting point is the DATE object is not getting created when i write  the below code
      var startDate = new DATE(oYear, oMonth, oDay);
    I am still not clear, that really the date object gets created in Adobe form If so the why the alert box is getting populated when i write below lines
    var oTemp = startDate.getFullYear();
    xfa.host.messagebox(oTemp);
    So, there are so many unclear things,
    If any one can help me by suggesting the approach and how to build the logic in the JavaScript I would be really thankful
    Regards
    PavanChand

    Hi,
    ChakravarthyDBA wrote:
    Hi
    I want number of Sundays between two dates
    example
    number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Here's one way:
    SELECT       early_date
    ,       late_date
    ,       ( TRUNC (late_date + 1, 'IW')
           - TRUNC (early_date,        'IW')
           ) / 7       AS sundays
    FROM       table_x
    ;This does not depend on your NLS settings.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Point out where the statment above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Ora-01847 day of month between 1 and last date of month coming in my query

    i m executing simple query but it is not working plz do help
    select *
    from sgvf_tree_nodes_vw
    where to_date(node_attr9_val, 'dd/mm/yyyy') between
    to_date('01/01/2010', 'dd/mm/yyyy') and
    to_date('31/12/2010', 'dd/mm/yyyy')
    gives : Ora-01847 day of month should be between 1 and last date of month

    Hi,
    Check the date format's once
    SQL> drop table demo;
    Table dropped.
    SQL> create table demo(val number, todate varchar2(12));
    Table created.
    SQL> insert into demo values(1,'04/11/2008');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from demo;
           VAL TODATE
             1 04/11/2008
    SQL> select sysdate from dual;
    SYSDATE
    03-FEB-11
    SQL> insert into demo values(1,'04/11/2010');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select *
      2  from demo
      3  where to_date(todate,'dd/mm/yyyy') between to_date('01/01/2010', 'dd/mm/yyyy') and to_date('31/12/2010', 'dd/m
    m/yyyy');
           VAL TODATE
             1 04/11/2010- Pavan Kumar N

  • Getting a list of all months between 2 DATE columns for a table

    Current set:
    IF OBJECT_ID('tempdb..#TEST') IS NOT NULL
    DROP TABLE #TEST
    CREATE TABLE #TEST
    ID INT,
    DOB DATE,
    EffectiveDate DATE,
    TerminationDate DATE,
    GCode CHAR(1)
    INSERT INTO #TEST
    VALUES
    (1043,'1/1/1970','1/1/2014','4/1/2014','S'), -- Active in month Jan,Feb,March,April
    (1051,'1/1/1989','3/1/2014','5/1/2014','P'), -- Active in month March,April,May
    (1070,'1/1/2010','5/1/2014','8/1/2014','G') -- Active in month May,June,July,August
    SELECT * FROM #TEST
    Expected result set:
    ID          Month         GCode
    1043      January      S
    1043      February    S
    1043      March         S
    1043      April           S
    1051      March        P
    1051      April          P
    1051      May          P
    ---- Similarly for ID 1070
    This is needed for the reporting and each ID will have points associated to it, that will be a separate column that I'll be adding. The reason that I want this result set is because, the user might say, how many points did the ID have for a particular month.
    The points are not going to change for an ID. Please let me know how to get the expected result set

    Try
    -- code #1
    set LANGUAGE English;
    set dateformat MDY;
    declare @Month table (N int, T varchar(20));
    declare @I int, @D date;
    set @I= 1;
    set @D= '1/1/2014';
    while @I <= 12
    begin
    INSERT into @Month values (@I, DateName(month, @D));
    set @I+= 1;
    set @D= DateAdd(month, +1, @D);
    end;
    SELECT ID, T, GCode
    from @Month as M inner join
    #TEST as T on M.N between Month(EffectiveDate) and Month(TerminationDate)
    order by ID, N;
    José Diz     Belo Horizonte, MG - Brasil

  • Create a table with all the months between two dates

    Hi all,
    I have a purchase table recording individual purchases. One of the fields is my Date field (date of purchase).
    I would like to create a table 'All_months' with two entries ('month_no' and 'month') which will be based on the first and last date in the purchase table. Assuming the first purchase recorded in my purchase table was on the 12th of January 2008, the table should have the following structure:
    month_no month
    1 12JAN2008
    2 12FEB2008
    3 12MAR2008
    It should continue in this fashion up-to the month where the last purchase was recorded.
    I have been struggling with creating the query that would do that for days now and can't find anything when asking Mr Google.
    Thanks,
    Chris

    Welcome to the forum!
    Here's one way:
    CREATE TABLE     all_months
    AS
    SELECT     LEVEL                    AS month_no
    ,     ADD_MONTHS ( first_date
                 , LEVEL - 1
                 )               AS month     
    FROM     (
              SELECT     MIN (date_of_purchace)     AS first_date
              ,     MAX (date_of_putchase)     AS last_date
              FROM     purchase
    CONNECT BY     LEVEL <= 1 + MONTHS_BETWEEN ( TRUNC (last_date,  'MONTH')
                                 , TRUNC (first_date, 'MONTH')
    ;Do you really need a table like this? Every time you change the data in the purchase table, you won't know if all_months is still accurate or not. You can derive all_months in a sub-query every time you need it, or make all_months a view instead of a table.
    Edited by: Frank Kulash on Jun 14, 2012 5:57 AM

  • How to calculate the number of months between two string as yyyymm

    Dear all,
    I have two month string like yyyymm e.g. 201003 -- 201105. Now I want to calculate the number of months bertween these two month string? How can I do that? Thanks.

    888099 wrote:
    Hi,
    Hope this will help :
         public static void main(String[] args) {
              Calendar cal1 = new GregorianCalendar(2010, 02, 01);
              Calendar cal2 = new GregorianCalendar(2011, 04, 01);
              int years = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);
              int months = cal1.get(Calendar.MONTH) - cal2.get(Calendar.MONTH);
              System.out.println("number of months : "+Math.abs(years*12 + months));
         }Or with only Strings :
         public static void main(String[] args) {
              String s1 = "201002";
              String s2 = "201104";
              int years = Integer.valueOf(s1.substring(0,4)) - Integer.valueOf(s2.substring(0,4));
              int months = Integer.valueOf(s1.substring(4)) - Integer.valueOf(s2.substring(4));
              System.out.println("number of month : "+Math.abs(years*12 + months));
         }Edited by: 888099 on 28 sept. 2011 05:49Full code solutions will not help the OP, he will be back here with a different Date question. Posters here try to nudge the OP to figure out the solution himself.

Maybe you are looking for

  • How to set transparency color in QT 7.0?

    Okay, I've been poking around the forums, searching and whatnot, and it looks like I can answer my own question [although please correct me if I'm wrong]: It's not possible, apparently, to set a transparency color for a video track in QT Pro 7.0. Des

  • Mir7 and duplicates credit memo invoices

    HI It is possible to block (show alert message) when I make credit memo in MIR7 with the same reference number and purchase number? In standard invoice this transaction show me message if in system exists already the same number reference. In this ty

  • I cant open firefox, everytime i click on it it just fades away!

    I have reinstalled it but it still doesn't work. And the little app thing on the pc, when i click it it just fades away. Can you please help!!

  • The call menu went missing in my unlocked Treo 65

    I am using an unlocked Treo 65o since 2007 without any issue. However, yesterday I was trying to purge the recent call log and the phone hanged and could not do anything. So I moved the battery out and restarted the PDA. I noticed the call menu was n

  • Crop interface is counterintuitive and needs correction.

    As it stands, the current crop 'tool' breaks its own user interface. One uses handles to manipulate the crop tool- reshaping and resizing it as desired. At the instant one has obtained a desired crop size and wants to move the crop tool around on the