Help - Date Range from a column

I have a column in one of my tables that contains the birthdate of a person and it's format is like this:
YYYYMMDD
sample ( 19740226 )
I need to find all the people who are between 35-45 years old from this date: 20080529
What would be the best way to do this, sorry new to date manipulation, thanks a lot of your help ahead of time.

Hi,
MONTHS_BETWEEN and TO_DATE are built-in functions. Like all built-in functions, you can learn about them by reading the SQL Language manual:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm
MONTHS_BETWEEN returns an "age" in months. In this case, it's more convenient to think in terms of years, so I divided the number of months by 12 to get the number of years.
I assumed table_name.column_name was a string in YYYYMMDD format, such as '19701231'. If any row has a value (NULLs are okay) that is not in this format, you will get a run-time error. For example, if a short string, like '197012', is encountered, you'll get the ORA_01840 error.
Apparently, that column is not in that format, at least not always. How you can get the information you need depends on exactly what is in that column. Find out what datatype it is (DATE, NUMBER, VARCHAR2), and, if it is not a DATE, post some samples of actual values.

Similar Messages

  • Reports / intranet/ In some detail,  the user will input a date range from and 2 and will out put the records in the int

    Hello there,
    I am totally green in web development.
    my goal is to, for the user will input a date range from and
    to and will out put the records in the intranet when they press a
    button.
    However, the good news is: I have experience in programming.
    I have written applications for desktop in VB>NET and I
    understand RDBMS /sql concepts .
    But CF and WEB development is new to me.
    My current projects involves in connecting to DB and testing
    it. (it works fine)
    And outputting reports by to a intranet page. (records)
    i need help on how to start this asap. I will even do some
    practice at home.
    Tools I have at work
    • Development server(test)
    • Home site.
    • Toad for db connection.
    • Html reference guide
    • Cf dummies book.
    How can start my projects.
    (ex. Create cf, outputpage?)
    seriously, I am new to this.
    Thanks.

    Well, I had a really nice response with some concepts and
    ideas for you to practise on etc, but these dumb forums timed out
    and I lost it all
    If you want to pop me an email we could probably do a few
    exercises together that way - or even by MSN Messenger if you want.

  • Function Module which will take Wekk No & Return date range (from & To dat)

    Hello everyone,
    I need a Function Module which will take Week No as an input Parameter & return me the date range
    (From date & To date of that week) .
    Thanks in advance!
    Cheers!
    Moderator message: date calculation questions = FAQ, please search before posting.
    Edited by: Thomas Zloch on Nov 2, 2010 5:25 PM

    Hi,
         Please write the below logic..
    data : v_date11 type sy-datum,
              monday    type sy-datum,
              sunday  type sy-datum,
              v_count1 type i .
    *v_count1 = 20 * 7.            "   Say U want details for 20th week , or give a parameter for week and multiply with 7*
    v_date11 = '20100101'.     "   take the starting day of the year ....
    v_date11 = v_date11 + v_count1.   " add to the date
    CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'   <-- call this FM
    EXPORTING
       DATE          = v_date11
    IMPORTING
      WEEK          = WEEK
       MONDAY        = MONDAY <-- will have the week starting day
       SUNDAY        = SUNDAY
    Regards,
    Srini.

  • Pass a date Range from VB to a parameter

    Hello,
    I'm thinking this is an easy question, but ...
    In a Visual Studio 2008 VB program, I'm allowing the user to pick a starting and ending date from DateTimePickers. (works fiine).
    In a CR 2008 report, I have a paramter defined as "pDateRange",  Type = date, Allow Range Values = Yes.
    In the Record Selection, I use a formula of {tblData.INSTALLDT} in {?Date_Range}.
    When I run the report, I can enter the date ranges in via the Enter Values prompt screen, and it works file,
    All I need to know is - how do I pass the dates the user selected in the VB program to the pDateRange parameter?
    Thanks very much,
    Carl

    Thanks Ludek for the reply.
    Unfortunately, I canu2019t seem to puzzle this out.  None of the examples seem to work.  This is an example, along with their comments.
    I get the error "The parameter field current values cannot contain range values because the ValueRangeKind property is set to discrete." on the last line.
    I could REALLY use some help getting past this issue.
           Dim myReportDocument As New CRS_Tab_Prod_Org_Cnt_Params2
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As ParameterValues
            Dim crParameterRangeValue As ParameterRangeValue
            crParameterFieldDefinitions = myReportDocument.DataDefinition.ParameterFields
            'Access the individual subreport parameter field "Date_Range"
            crParameterFieldDefinition = crParameterFieldDefinitions.Item("Date_Range")
            'Cast the variable to hold the values to pass to the Report before execution
            crParameterValues = crParameterFieldDefinition.CurrentValues
            'Cast the variable to hold the range value for the parameter
            crParameterRangeValue = New ParameterRangeValue()
            'Set the Date range and include the upper and lower bounds. Use the Cdate function as insurance
            'to ensure that the value passed is cast to the appropriate data type
            With crParameterRangeValue
                .EndValue = CDate("1/1/1997")
                .LowerBoundType = RangeBoundType.BoundInclusive
                .StartValue = CDate("12/20/1997")
                .UpperBoundType = RangeBoundType.BoundInclusive
            End With
            'Apply the Date range to the values to be passed to the Report
            crParameterValues.Add(crParameterRangeValue)
            'Pass the parameter values back to the report
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
    Thanks for your help,
    Carl

  • Calculated Date Range in Lookup Column

    I want to have a lookup column on a list called Report Week.  The report week is a date range between Sun and Sat.  I could easily make a column of ranges in a seperate list and then use it as a lookup but I am hoping for something more
    elegant.  What I envision is the user selecting the Date Range lookup in a list item and the date ranges shown are the previous, current and upcoming weeks.  So the dropdown list would look like this:
    09/20/14 - 09/26/14
    09/27/14 - 10/03/14
    10/04/14 - 10/10/14
    Can this be done w/out using .NET?  Thanks in advance.

    more or less, you need three calculated columns (well, you may be able to do it in just the one, but it'll be obnoxious to write the formulas)...
    - start date
      => DateAdd([date field], 0 - (dayofweek([datefield]))
            basically, subtract the day of week from the reference date... this should give you the sunday that starts the week
    - end date
      => DateAdd([date field], 7 - (dayofweek([datefield]))
            basically the same, except this adds the remaining number of days in the week, to give you the saturday that ends the week
    - range (description)
      => concatenate([start date], " - ", [end date])
    you may need to fiddle with the formulas a little bit... run them in excel to tweak them.
    Scott Brickey
    MCTS, MCPD, MCITP
    www.sbrickey.com
    Strategic Data Systems - for all your SharePoint needs

  • SqlQuery Help [date range]

    Database: Oracle 10g
    Table: SOURCE_TABLE
    #of records: 500k
    Primary Key: ID, EFF_DATE
    Data/Table:
    with SOURCE_TABLE AS
         (select 'P1' AS ID, TO_DATE('03/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V1' AS VALUE1, 'V2' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P1' AS ID, TO_DATE('02/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V3' AS VALUE1, 'V24' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID, TO_DATE('01/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID, TO_DATE('03/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V11' AS VALUE1, 'V21' AS VALUE2 FROM DUAL)                                 
    SELECT * FROM SOURCE_TABLE  Conditions:
    For a given date range i.e. 01/01/2012 to 04/30/2012
    what we need is: For each ID, we need part "P" value1 and value2 column values for each specific month between the default date ranges.
    In this case it would be Jan-2012, FEB-2012, MAR-2012, APR-2012
    If you see below output for P1, there will not be JAN-2012 record as the part P1 is effective from FEB-2012
    What i have done so far:
    i have the select query basically it is looping through 01/2012 to 04/2012 and for every month,
    find out the max eff_date record less then the month that we are computing the value columns for
    Output:
    with output as
         (select 'P1' AS ID , '02/01/2012' AS AS_OF_DATE, 'V3' AS VALUE1, 'V24' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P1' AS ID , '03/01/2012' AS AS_OF_DATE, 'V1' AS VALUE1, 'V2' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P1' AS ID , '04/01/2012' AS AS_OF_DATE, 'V1' AS VALUE1, 'V2' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '01/01/2012' AS AS_OF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '02/01/2012' AS AS_OF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '03/01/2012' AS AS_OF_DATE, 'V11' AS VALUE1, 'V21' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '04/01/2012' AS AS_OF_DATE, 'V11' AS VALUE1, 'V21' AS VALUE2 FROM DUAL
    SELECT * FROM OUTPUT;
            ID     AS_OF_DATE     VALUE1     VALUE2
         P1     02/01/2012     V3     V24
         P1     03/01/2012     V1     V2
         P1     04/01/2012     V1     V2
         P2     01/01/2012     V10     V20
         P2     02/01/2012     V10     V20
         P2     03/01/2012     V11     V21
         P2     04/01/2012     V11     V21Thanks in advance

    Hi,
    ora1001 wrote:
    Hi frank,
    I changed the query to inner join instead of outer join because if a part is not effective for a given month, then i dont need a record.
    ex: if P1 EFF_DATE IS 03/01/2012, then i dont need records for JAN, FEB... You're right; inner join is all you need here. My mistake.
    What is "P1 EFF_DATE"? Is that the start of the date range you're interested in (January 1, 2012 in your original example)?
    Don't you still need to cosider rows before that date? For example, say we want to show the same 4 months (January to April, 2012), but instead of
    select 'P2' AS ID, TO_DATE('01/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUALthe data is changed to
    select 'P2' AS ID, TO_DATE('11/01/2011','MM/DD/YYYY') AS EFF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUALWould you still want the same results? In this example, the values from November 2011 serve as the values for January and Febrruay 2012. It doesn't matter that Noverber 2011 is outside of the target range.
    It works fine... its faster now.
    however, i would like to know the difference in my query vs your query in terms of performance..
    the subquery runs faster when compared to analytic function...
    select * from part p,
    source_table st
    where p.id = st.id
    and st.eff_date = (select max(eff_date) from source_table st1
    where st1.eff_date < '01-mar-2012');
    If st1.eff_date is a DATE, then don't try to compare it to a VARCHAR2, such as '01-mar-2012'. Use TO_DATE:
    where st1.eff_date < TO_DATE ( '01-mar-2012'
                                   , 'DD-mon-YYYY'
                        )or a DATE literal:
    where st1.eff_date < DATE '2012-03-01'instead.
    vs
    select * from (
    select p.id,
    st.eff_date,
    row_number() over (partition by st.id,st.eff_date order by st.id,st.eff_date desc) as consider_order from part p,
    source_table st
    where p.id = st.id) where consider_order = 1;
    The first approach is doing much less work. It just has to remember what the latest eff_date is. Say it has already found a row with March 1, 2012, and it comes across a row with an earlier date, such as January 1, 2012. As soon as it sees that January 1, 2012 is not the new record holder, it can move on to the next row. (Using the LAST function, as I suggested, would cause it to do even less work.)
    The second approach is doing much more work. It has to remember all the dates, in order. Say it has already found a row with March 1, 2012, and it comes across a row with an earlier date, such as January 1, 2012. After it sees that January 1, 2012 is not the new record holder, it still has to determine if January 1 comes 2nd, or 3rd on the list.

  • Select Between two date ranges from xml file

    Hi ,
    I have a column date_ with datatype VARCHAR2(150) it stores
    data as
    05/19/2010 11:23 AM
    05/20/2010 12:23 PM
    05/22/2010 11:23 AM
    05/25/2010 11:23 AM
    i have to select all the rows between 05/19/2010 and 05/22/2010 how to do that this column is in xml file

    I have a table wit two fields
    Field1 is integer and field2 is xmltype
    in the xmltype i store an xml file
    <ParentNode>
    <Node>
    <Cat>1</Cat>
    <Date>05/19/2010 11:23 AM </Date>
    </Node>
    <Node>
    <Cat>2</Cat>
    <Date>05/20/2010 12:23 PM </Date>
    </Node>
    <Node>
    <Cat>3</Cat>
    <Date>05/22/2010 11:23 AM </Date>
    </Node>
    </Parentnode>
    I am using teh below query to retrive teh result
    SELECT T.Feild1, XML.* FROM Tablename T,
    XMLTable( 'Parentnod/Node' PASSING T.Feild2 COLUMNS Cat NUMBER PATH 'Cat' ,
    DATE_ VARCHAR2(100) PATH 'Date'
    )XML where cat >1;
    now i have to do teh same to select the rows between two date range 05/19/2010 and 05/21/2010
    hope i am able to make teh question simple

  • Passing DateArray or Date Range from formula result to Select Expert

    Is there a way to pass Two (2) dates from a single formula to the Select Expert?
    I calculate Beginning and Ending dates of periods ie: fiscal year to date, calendar year to date, last calendar quarter.  I would like to pass both the beginning and end date to a formula in the Select Expert.
    Please show code samples if possible.
    Thanks

    In your selection criteria, have code similar to this:
    datevar begindate;  // this is from your formula for date range
    datevar enddate;  // this is from your formula for date range
    {database.datefield} in begindate to enddate;
    Edited by: Sanjay Kodidine on Jun 27, 2009 11:43 AM

  • Date range From Fiscal period range

    Hi All,
    How can we get the date range for a given fiscal period range?
    please help.
    Thanks
    Gaurav Mittal

    hi
    good
    pls check this code
    declare a range like
    ranges: r_date for s021-spmon. (declare as per your data type for the date)
    in initialization event write.
    r_date-low = '012007'. (enter the required lower range of value)
    r_date-sign = 'I'.
    r_date-option = 'BT'.
    r_date-high = '122007'.
    append r_date.
    now use the r_date field in the program code.
    thanks
    mrutyun^

  • Data merge from two columns

    Hello all,
    We have a requirement that we need to combine data from two columns. We have comments1 field in TABLE A and comments2 and comments3 fields in a TABLE B. The the report has a condition:
    Begin
    If status = 'Pre-Award' then
    Print comments1 from TABLE A;
    ELSIF
    status = 'Post-Award' then
    Print comments2 and comments3 from TABLE B;
    END IF
    END
    Tools version: Oracle reports version 6i.
    Thanks in advance.
    Arun.

    There's a couple of ways to do this.
    One way would be to create a placeholder column for your comments.
    The create a function (much like what you have already listed) to determine which comments to use and place the value of that comment into your placeholder column. You can then use it in that group just as you would any other field.
    Chad

  • How to convert Date,month,date range row to column

    hi experts
    i have a requirement like
    i want to change date, month and if user key in date range (01-04-2010 to 31-04-2010) then o/p like below
    1st-o/p-format
    d1 d2 d31
    01-04-2010 02-04-2010 ------------------------------- 31-04-2010
    2nd-o/p-format -based on transaction month
    d1 d2 d31
    jan feb ------------------------------------------ mar
    3rd-o/p-format date range based on transaction date
    d1 d2 d31
    01-04-2008 02-04-2010 -------------------------------31-04-2009
    Note :Basically i want to display these formate in Oracle Forms then based these dates i want to fetch record like below:
    d1 d2 d31
    jan feb dec
    count sales amt avgsales count sales amt avgsales ------------------ count sales amt avgsales
    so can anyone tell me what approach i shouls apply..
    Thanks
    abhishek

    This forum is titled "Certification" - pl post in the PL/SQL or Database General forums for a better/faster response.
    HTH
    Srini

  • Calculate the date range from entered date

    HI
    My requirement is to get the data in a perticular intervals of posting date.
    Directly we can create a variable with interval on posting Date to have the required data but Here we need two have two varibles because in one varibale user enters posting date and in second variable user enters any number like 1,2,3....etc
    Let's say user enetered posting date as 30.08.2010 in the first variable and number 4 in the second variable.
    Finally out put range should be calculted from entred posting date 30.08.2010  date to four days back  
    i.e output  should be appear in the report  from 27.08.2010 to 30.08.2010.
    My question i can create first avariable on posting Date but  where shoud i create the second variable on which field.
    Please help me on this..points will be awrded.
    Regards,
    Siva Thottempudi.

    R you talking about the below to create new variable on the existing key figure
    Selecting Variables
    When you select characteristic values in the query definition, you can also select variables instead of fixed values. These act as placeholders and are only filled with fixed values when the query is executed.
    When selecting variables, you can also define new variables, change variables, or delete variables. These functions are always available to the right of the selection of the variable type.
    Selecting Variables
    1.      Choose Show ® Variables.
    2.      Under Type, select the variable type (such as Characteristic Value Variable, Hierarchy Node Variable) from which you want to select the variable.
    3.      Select one (or, in exceptional cases, more than one) variable from the list of available variables in the left window and add them (using the right arrow) to the right Selection window.
    Selecting Variable Value Range Limits
    1.      Choose Show ® Value Ranges.
    2.      Select your required operator from the dropdown box. You can choose from the following operators:
    ○       Between
    ○       Less Than or Equal to
    ○       Greater Than or Equal to
    ○       Less Than
    ○       Greater Than
    3.      Select the required value or values for the value range and choose . The input help appears in a new dialog box and displays the selection of variables under Show  ® Variables.
    4.      Under Type, select the variable type (such as Characteristic Value Variable, Hierarchy Node Variable) from which you want to select the variable.
    5.      Select the required variable and choose OK.
    6.      For the Between operator, two single values are required for the interval limits; the system automatically displays two dropdown boxes. In this case, repeat steps 3-5.
    7.      After you have set the value range, choose OK.
    8.      Add the selection to the right Selection window using the right arrow.

  • Determining Date Range from Pay Date Information

    I have a table of employees with different pay dates because they are college interns and they leave at different dates, so their most recent pay date will be different. I have created a query to find the most recent pay date.  The pay periods are bi-weekly.
    I have a table called tblPayPeriods with all of the pay dates. I have created a query that pulls the most current pay date for each intern and I want to match that pay date to the pay date of the Pay Periods table and increment back twenty pay periods. 
    Once I have determined the oldest pay date I want to use that range for a calculation for average hours ultimately.  I can handle the average hours part but I'm having trouble with the pay dates part of this. Any suggestions would be appreciated. 
    Thanks!
    Here is the SQL statement to find the most current pay date for each intern:
    SELECT tblMeasurementPeriod.EENum, Max(tblMeasurementPeriod.[Pay Date]) AS [MaxOfPay Date]
    FROM tblEmployees INNER JOIN tblMeasurementPeriod ON tblEmployees.[EE Num] = tblMeasurementPeriod.EENum
    WHERE (((tblEmployees.[Measurement Period])="initial"))
    GROUP BY tblMeasurementPeriod.EENum;
    Here is the SQL statement using the query joined to the pay date table:
    SELECT qryFindLatestPayDateforINITIAL.EENum, qryFindLatestPayDateforINITIAL.[MaxOfPay Date], tblPayDate.[Pay Date]
    FROM qryFindLatestPayDateforINITIAL INNER JOIN tblPayDate ON qryFindLatestPayDateforINITIAL.[MaxOfPay Date] = tblPayDate.[Pay Date];
    Alicia Hunsberger

    You have the Intern Last Pay Date (LPD)
    You want to match that LPD to the pay date of the Pay Periods table...
    ** so the first question is - are you able to? what is the obstacle on this?
    and increment back twenty pay periods
    ** is there a fixed math you can rely on, such as subtract 180 days?...will that work to determine the pay date 20 periods previously?  it would be great if the pay periods had a sequential integer in their record - - - that would make it easy....

  • [DIAdem] How can I trace a data range from a data channel?

    Hello,
    I am looking for a way to trace a range of data from a data channel using DIAdem script.
    Right now, I can only trace an entire data channel.
    Is it possible? I do not want to split a data channel in order to trace a part of it...
    Thank you.
    Regards

    Hello Tenanio,
    I believe this will answer your question:
    I am assuming in my code that you have a VIEW layout with a sheet called "Sheet 0" which has a 2D-graph in the top area (as can be seen from the screenshot below):
    Copy this Code into SCRIPT and run it, it should display the data the way you had described:
    View.Sheets(1).Cursor.Type = "Band"
    View.CoordinateWnd.Visible = TRUE
    View.ActiveSheet.Cursor.X1 = ChD(305,"Date_Mesure")
    View.ActiveSheet.Cursor.X2 = ChD(320,"Date_Mesure")
    View.Sheets("Sheet 0").Areas("Area : 1").DisplayObj.XScalingMode = "RangeScroll"
    call wndshow("View")
     Please let me know if this works for you and if you have any additional question.
           Otmar
    Otmar D. Foehner
    Business Development Manager
    DIAdem and Test Data Management
    National Instruments
    Austin, TX - USA
    "For an optimist the glass is half full, for a pessimist it's half empty, and for an engineer is twice bigger than necessary."

  • Help with PowerShell to delete a date range of Calendar meetings

    I'm trying to delete all Calendar items within a date range, from a mailbox. But first I'd like to just make sure my date filter is actually working.
    Here is what i HAVE working:
    Search-Mailbox ME -SearchQuery "Received:01/01/2010..03/18/2010" -EstimateResultOnly
    This works, it gives me a count of all things in my mailbox
    Search-Mailbox ME -SearchQuery kind:meetings -EstimateResultOnly
    This works, it gives me a count of all Meetings in my Calendar.
    I reallly need now to get the date range to work in conjunction with the kind:meetings.
    How can I do that?

    Hi,
    The results include the deleted meetings. I test it in my lab.
    So the command to delete Calendar meetings with a date range is this:
    Search-Mailbox "username" -SearchQuery "Received:01/01/2010..3/18/2015 kind:meetings" –EstimateResultOnly -DeleteContent
    Best Regards.
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]
    Lynn-Li
    TechNet Community Support

Maybe you are looking for

  • One domain, 2 sites but I only want one of them!!

    I hope someone can help. My laptop was stolen earlier this year. At that point I was unaware of how to transfer my website created in iweb to another computer and so created a new website. I was actually quite happy to do this as the old website had

  • Jsp form help

    Hello everyone out there' I am a computer science teacher in a private high school in Nigeria and have some experience in java programming language and also new to the JSP tech .I want to introduce the school into using web applications in managing t

  • Error while mapping Views

    When running the OMWB, the process will hang while trying to map the views. I have let it run overnight and it will still not move. Upon further examination of the error files, I got this error: java.lang.NoSuchMethodError      at oracle.mtg.sqlserve

  • All of my old notes disappeared after upgrading to ios 6.1, how do I get them back?

    I upgraded by iPhone 4s and iPad 2 to IOS 6.1.  Now all of my old notes are gone. Is there a way to retrieve them? Thanks, Marti Garner

  • Sending to a friend in Web Gallery

    Once you have selected Tell A Friend from Web Gallery, is there any way to check and see if it was actually sent as in Mail with the Sent folder?