Convert date to date format VARCHAR2 format NUMBER

Hello

I use Oracle 10 g R2 on IBM AIX v5.0 on the Windows machine.

Not able to get the query to work below.
select count(*)
from error_data e1
inner join error_item e1 on e1.error_id = e2.error_id
where to_char(e1.CREATED_DATE) >= to_char(to_date(from_date,'YYYY-MM-DD HH24:MI:SS'),'YYYYMMDD') AND to_char(e1.CREATED_DATE) < to_char(to_date(to_date,'YYYY-MM-DD HH24:MI:SS'),'YYYYMMDD')
and TO_CHAR(e1.created_time) >= to_char(to_date(from_date,'YYYY-MM-DD HH24:MI:SS'),'HH24MISS') AND to_char(e1.CREATED_time) < to_char(to_date(to_date,'YYYY-MM-DD HH24:MI:SS'),'HH24MISS')
It doesn't give me a correct output. He should give me the number of errors occurs between the time (i.e. from_date to to_date).

The type of the column is as shown below.

CREATED_DATE = NUMBER
CREATED_TIME = NUMBER
from_date = VARCHAR2 (100) [it would be in the format as "2010-09-21 08:00 ' ']
TO_DATE = VARCHAR2 (100) [it would be in the format as "2010-09-22 08:00 ' ']

I can not change the type of from_date and to_date columns.

Please provide a way to ensure that I get this operational application.

Thanks in advance.

user9963922 wrote:
Unable to get the output with the suggestions above, also good friends.

Oops, silly me. You can't compare the date and time separately to get meaningful results. Use:

select  count(*)
  from  error_data e1
        inner join error_item e1 on e1.error_id = e2.error_id
  where to_date(e1.CREATED_DATE || to_char(e1.created_time,'000000'),'YYYYMMDD HH24:MI:SS') >= to_date(from_date,'YYYY-MM-DD HH24:MI:SS')
    and to_date(e1.CREATED_DATE || to_char(e1.created_time,'000000'),'YYYYMMDD HH24:MI:SS') <  to_date(to_date,'YYYY-MM-DD HH24:MI:SS')
/

SY.

Published by: Solomon Yakobson, Sep 22, 2010 05:05

Tags: Database

Similar Questions

  • Convert date format

    How to convert date format

    23/03/2010 to March 23, 10

    I'm passing date front end which is the format 23/03/2010 and happens in a query, and I do not get the results in the table it's March 23, 10

    How to apply the conversion of this attribute

    First to view the description of the column attribute_date1 table

    If its data varchar2, date, or timstamp type

    If attribute_date1 is the data type date

    Select * from mst_pindetails where attribute_date1 = to_date (March 23, 10 ',' DD-MON-RR')

    If attribute_date1 is varchar2

    Select * from mst_pindetails where to_date (attribute_date1, "DD-MON-RR') = to_date (March 23, 10 ',' DD-MON-RR')

  • convert date format period

    Hi all

    Here are my existing query which I run another tool to extract data from oracle-

    Select * from transactionTbl

    WHERE

    DATE > = TO_DATE (' $(vAppStartDate)', "DD/MM/YYYY")

    AND DATE < = TO_DATE (' $(vAppEndDate)', "DD/MM/YYYY")

    variables-

    -vAppStartDate = 06/01/2014

    -vAppEndDate = 30/06/2015

    Rather than use the Date column in the WHERE condition, I want to use PeriodID of column existing in the same table, to make the query faster.

    The period column is in below format.

    PeriodID format-> 201294 //means 2012Q 4. So 9 means Q

    Since I'm on variables, the values are always to the date format, so my requirement is first change variable date from periods of format.

    I wrote the pseudo-code, because I of course know how to convert date format periodID. Q also means in the periodID 9.

    Select * from transactionTbl

    WHERE

    PeriodID > = period_function (TO_DATE (July 1, 14 ',' DD/MM/YYYY '), 'YYYYxx')

    AND PeriodID > = period_function (TO_DATE (July 1, 15 ',' DD/MM/YYYY '), 'YYYYxx')

    Please help me with the query.

    Thank you!

    Calling a user-defined function is likely to slow down your query.

    What's the problem with just using regular date formatting strings for example

    SQL > select to_char (to_date('15/09/2014','DD/MM/YYYY'), 'YYYY "9" Q') of double;
    TO_CHA
    ------
    201493

    1 selected line.

  • convert date format dd.mm.yyyy jj.mm.AA

    Hi all

    My need is to convert date format dd.mm.yyyy jj.mm.AA. All years are 1999 or less. My first assumption is to use the combination of substr with concatination of '19', but maybe someone can suggest another decision.
    select '18.03.97' as dt from dual

    You can do this:

    SQL> select to_char(to_date('18.03.97','dd.mm.rrrr'),'dd.mm.rrrr') Result from dual;
    
    RESULT
    ----------
    18.03.1997
    
  • How to convert Date format in the Apex?

    Hi all

    I created an element of Apex Date Picker as "yyyy-mm-dd", now when they select this date picker, that must be converted in "day, month, DD, YYYY".
    I trired like that but it does not work, can anyone help me to find things to do.

    Under article, we have free will.

    Default value: to_char (to_date (: P1_ENG_DATE, 'dd-mm-yyyy'), ' day, month DD, YYYY ")
    Deafult value as type - PL/Sql.

    Thanks,
    David...

    Hello

    You can set the date format level of application, then you don't need to specify the format each time.

    for this go to "Modify the Application Properties"-> globalization

    Here you can specify the format of date of application.

    Thank you
    Tauceef

  • convert Date format MMM DD YYYY to DD/MMMM yyyy

    Hello

    I'm in the studio EN 11.1.2.1... We have an obligation to display the date in the format yyyy MMMM dd is lets say 10 January 2015 should display as 10 January 2015

    Members exist in Essbase outline: creation Date

    The Member is used in the grid and the value of the cell is displayed in a block of text as < < GetCell("Grid1",1,A,1) > >

    I don't see the preference option to set as DD/MMMM YYYY format that is available for System Date function < < Date (jj/aaaa "MMMM") > >


    I also tried with true measures typed and activate the date format, but it does not work in EN report and it seems that the preferred default setting takes precedence.

    Untitled.png

    any suggestion will help...

    Thank you

    KP

    It resolved, post the answer might help someone in the future...

    good to know that the file-> preferably in the workspace can be changed... DD MMMM YYYY gives me the date to January 10, 2015 according to my expectations.

    I changed the Date in the file format-> preference for the financial report

  • How to automatically convert date format

    My question is that the definition fix date format for form hole, assume I get the data in the date column
    the date should be automatically format how in this example, type 01012010 only when I press ENTER after that show both 01/01/2010. but do you remember the shape of the hole because I don't want to enable it for each column.

    I also tried on after change and after query, but it does not work.

    Dear Sir

    I already mentioned in my coding read carefully, you must create a form level, think how is possible, you define triggers above level of the item and work for the shape of the hole.

    Thank you

  • How to convert date format in number?

    I have a sql like this:
    select to_date('MAR','Mon', 'NLS_DATE_LANGUAGE=American') m from dual
    I want to display "3" instead of showing the Mar...
    I tried to use to_char(date,'MM'), but the result will return '03'.
    I would like to have the output exactly equal to 3.

    Thanks Bros.

    920575 wrote:
    I have a sql like this:

    select to_date('MAR','Mon', 'NLS_DATE_LANGUAGE=American') m from dual
    

    I want to display "3" instead of showing the Mar...
    I tried to use to_char(date,'MM'), but the result will return '03'.
    I would like to have the output exactly equal to 3.

    3 (without the single quotes) is a NUMBER. It is exactly equal to the NUMBER 03.
    "3" is a string. It isn't equalt to the string '03'.
    Do you want a NUMBER or a string?

    If you want the chain of characters-1 '3', use 'FMMM"instead of"MM ".

    select  TO_CHAR ( to_date ('MAR', 'Mon', 'NLS_DATE_LANGUAGE=American')
                    , 'FMMM'
                    )   AS m
    from    dual
    

    To_char sometimes add padding (sometimes spaces, sometimes ' 0) for elements a constant width. For example, a few months need 2 characters for the "MM" format, then, TO_CHAR default, buffers left with '0' to do monthly 2 characters, whether or not they have need of 2 characters. With the help of "FM" (case sensitive) IN the format string change whether or not this kind of padding will be added.

    You could also use LTRIM to remove leaders ' 0 in this case, but why delete them when it is easier, is not to generate them in the first place?

  • Convert date format timestamp format

    Hello, I have the following code in * impl.java in the doDML method. I'm getting "invalid column type" at run time, but when I click on insert. I think that the problem is because I do not convert the timestamp format format date correctly. Any help please?

    CallableStatement cs1 = null;

    try {}

    / * Some code here * /.

    d = new java.sql.Date java.sql.Date (this.getRbcDtFrom () .getTime ());

    CS1. SetDate (2, d);

    java.sql.Date d1 = new java.sql.Date (this.getRbcDtTo () .getTime ());

    CS1. SetDate (3, d1);

    CS1. SetString(4,"RBCS");

    CS1. SetString (5, this.getRbcCode ());

    CS1.setInt (6, getRbcCounter ());

    CS1. ExecuteUpdate();

    Boolean ValeurRet = cs1.getBoolean (1);

    If (retvalue)

    {

    super.doDML (operation, e);

    }

    else {}

    System.out.println ("no Commit!");

    }

    } catch (SQLException f) {}

    throw new Aexception.getLocalizedMessage (f);

    }

    You did not created wrapper fucntion.

    Take a look at:

    Troubleshooting

    Use the same principle for the registered function...

  • Convert number to date format

    HI team,

    I have a problem, how we can convert number in date format?
    This is the result of the query.

    SQL > col START_TIME for 999999999999999999999999
    SQL > select start_time in qrtz_triggers;

    START_TIME
    -------------------------
    1364243906000
    1364589406000

    So, I have to change the date format niumber rto.

    My date format as for example: "" Mar 25,2013 20:36:45 ""


    Please suggest me...
    Thank you
    Chavigny

    Published by: 939938 on March 14, 2013 06:39

    This is the number of milliseconds since January 1, 1970.

    SQL> SELECT to_char(to_date('01/01/1970','mm/dd/yyyy')+1364243906000/24/60/60/1000
      2  ,'Mon dd, yyyy hh:mi:ss PM') FROM dual;
    
    TO_CHAR(TO_DATE('01/01/1970','
    ------------------------------
    Mar 25, 2013 08:38:26 PM
    

    So in your query instead of start_time use
    TO_CHAR (to_date (' 01/01/1970 ',' mm/DD/yyyy') + start_time/24/60/60/1000,' Mon DD, YYYY HH: mi: ss PM "")

    Published by: kendenny on March 14, 2013 08:31
    Had used mm instead of e for the minutes.

  • varchar2 to the date format conversion

    I have converted the formats of date several times, but for some reason, I get an error invalid number when you try to convert a varchar2 column. I tried the to_char and to_date function and I get the same result. The column is a date and it is formatted like ME-DD-YYYY, but I want to change it to DD/MM/YYYY. My query is below:

    Select to_date('fccpdate','MM/DD/YYYY')
    of cc_class_scmast_v

    When I try to_date I get this:

    Error from the 1 in the command line:
    Select TO_DATE ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01858: a non-digit character was found here where was waiting for a digital
    01858 00000 - "a non-digit character found here where was waiting for a digital".
    * Cause: Input data to convert using a date format model has been
    incorrect answer. The input data did not contain a number where is a number
    required by the format model.
    * Action: Fix the input data or the date format model to ensure that the
    elements correspond to the number and the type. And then try the operation again.



    When I try to_char I get this:

    Error from the 1 in the command line:
    Select TO_char ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01722: invalid number
    01722 00000 - "invalid number."
    * Cause:
    * Action:


    I tried to remove the single quotes of my column and that does make a difference. Any help is appreciated.

    Hello

    housetiger77 wrote:
    I have converted the formats of date several times, but for some reason, I get an error invalid number when you try to convert a varchar2 column. I tried the to_char and to_date function and I get the same result. The column is a date and it is formatted like ME-DD-YYYY,

    If the column is a DATE, then it has the same format that all DATEs, which is nothing like 'DD-MON-YYYY '. Formats like which apply only to chains.
    Conversely, if it is in the format "DD-MON-YYY", then it is a string, not a DATE.

    but I want to change to DD/MM/YYYY. My query is below:

    Select to_date('fccpdate','MM/DD/YYYY')
    of cc_class_scmast_v

    To_date (x, "MM/DD/YYYY") tries to convert the string x in a DATE. Let's say it starts by taking the first 2 characters of x, for the month. The first 2 characters of 'fccpdate' are "fc", which is not a valid number (at least not in base 10), not to mention a number from 1 to 12, TO_DATE so will raise an error.

    When I try to_date I get this:

    Error from the 1 in the command line:
    Select TO_DATE ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01858: a non-digit character was found here where was waiting for a digital
    01858 00000 - "a non-digit character found here where was waiting for a digital".
    * Cause: Input data to convert using a date format model has been
    incorrect answer. The input data did not contain a number where is a number
    required by the format model.
    * Action: Fix the input data or the date format model to ensure that the
    elements correspond to the number and the type. And then try the operation again.

    When I try to_char I get this:

    Error from the 1 in the command line:
    Select TO_char ('fccpdate ',' MON-DD-YYYY "") of cc_class_scmast_v, where fccpdate IS NOT NULL
    Error report:
    SQL error: ORA-01722: invalid number
    01722 00000 - "invalid number."
    * Cause:
    * Action:

    I tried to remove the single quotes of my column and that does make a difference. Any help is appreciated.

    It's a good first step. Literals are enclosed in single quotes are not identifiers (including the column names). "fccpdate" is the literal string of 8 characters containing 'f', ' c; Another 'c', 'p' 'd', 'a', 't' and 'e'. " fccpdate (without the single quotes) can be the name of a column.

    If fccpdate is a string, as July 18, 2012', then you can convert it to a DATE using TO_DATE.

    TO_DATE (fccpdate, 'DD-MON-YYYY')
    

    If you want to display a DATE in a particular format, use

    TO_CHAR ( d
            , f
            )
    

    where d is a DATE, and f is the format string. In this case, d is perhaps the TO_DATE expression above

    TO_CHAR ( TO_DATE (fccpdate, 'DD-MON-YYYY')
            , 'MM/DD/YYYY'
            )
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    See the FAQ forum {message identifier: = 9360002}

  • Date Format converting... Help, please

    Hello

    I have a date column in the table, which has two formats and the data type of the column is varchar2, how to convert them to a format.

    Example of data as below:

    1. 1 OCTOBER 12 12.00.00 AM

    2.02 / 11/2015 12.00.00 AM

    Help me please to convert them to the format (DD/MM/YYYY HH)

    Originally, you started with

    Example of data as below:

    1. 1 OCTOBER 12 12.00.00 AM

    2.02 / 11/2015 12.00.00 AM

    In your error report, it reads

    INSERT INTO TEST VALUES (11 NOVEMBER 14 09:26:25 "");

    INSERT INTO TEST VALUES ('2014-01-31 23:33:25 ');

    INSERT TEST VALUES (OCTOBER 14, 2014 05:44:55 ');

    While initially it was possible to establish a distinction between the formatted strings differently based on the occurrence of a hyphen in each case a dash, it is no longer possible with your examples of more recent data.

    In addition, your second line of input currently requires "HH24" to the address of the value of the time correctly.

    With the updated data and the General advice to store dates in DATE columns, you could try the long

    ALTER TABLE TEST ADD(ACTION_DATE_NEW DATE);
    UPDATE TEST SET ACTION_DATE_NEW = CASE
      WHEN LENGTH(ACTION_DATE) = 18 THEN TO_DATE(ACTION_DATE, 'DD-MON-YY HH24:MI:SS')
      WHEN LENGTH(ACTION_DATE) = 19 THEN TO_DATE(ACTION_DATE, 'YYYY-MM-DD HH24:MI:SS')
      WHEN LENGTH(ACTION_DATE) = 20 THEN TO_DATE(ACTION_DATE, 'DD-MON-YYYY HH24:MI:SS')
    END;
    COMMIT;
    

    and continue from there.

    See you soon

    Kirk

  • Validation - validate if the field has a date format appropriate or a number

    Hello

    I have 2 of my form fields... we're the date type and the other is of type number... may I know how to validate if the field has the correct date/number format...

    Please advice how to write "Validation" of the APEX feature to accomplish the foregoing.

    Thank you

    can I know how to validate if the field has the correct date/number format...

    The most effective way is simply to try to convert to the type required (using format masks there) in a function to return a Boolean validation:

    declare
    
      n number;
    
    begin
    
      n := to_number(:p1_num_item);
    
      return true;
    
    exception
    
      when value_error or invalid_number
      then
        return false;
    
    end;
    

    and

    declare
    
      d date;
    
    begin
    
      d := to_date(:p1_date_item, 'DD-MON-YYYY');
    
      return true;
    
    exception
    
      when others
      then
        if sqlcode between -1899 and -1800
        then
          -- Date format error
          return false;
        else
          -- Unexpected error
          raise;
        end if;
    
    end;
    

    my date is in the following format: DD-MMM-AA

    There is no format 'MMM' model. And do not use 2-digit year formats: which caused bad enough already.

  • Convert the Period_Name in GL_JE_Lines table to a date format and then come back year

    I'm working on a data model BI Publisher and I try to convert the Period_Name in GL_JE_Lines table to a date format and then return of the year.

    The sql below works in 11i, but I can't make it work in Fusion.

    to_char (to_date (l. )) period_name , ' MON-RR ' ),'YYYY')

    Any ideas?

    Hi Jennifer,.

    To_char (sysdate, 'DDMONYYYY') in BI Publisher does not return a correct results due NLS_DATE_FORMAT/DATE_LANGUAGE settings.

    According to the standards of the I18N, NLS_DATE_LANGUAGE in the database is still hardcoded to NUMERIC_DATE_LANGUAGE. NUMERIC_DATE_LANGUAGE 'MY' in a date format mask is an integer, so you see the correct value.

    You're not supposed to publish direct SQL with fixΘe format masks (unless it's some sort of canonical format used in internal processing, including the end-user will not be), you should return language digital date to the mid range and then make the formatting of y.

    Workaround

    Try adjusting the NLS_LANGUAGE in SQL data model to override formatting from of the

    Data base and values of the Session, for ex: select to_char (sysdate, 'MON-DD-YYYY', 'NLS_DATE_LANGUAGE = AMERICAN') of double;

    I got this Oracle support after lifting a SR.

    Thank you

    Rahul.

  • Convert char to date format in obiee 11g?

    Hello

    I want to convert char to date format in obiee 11g.

    I have this date

    ' 07/31 /' | CAST (YEAR (CURRENT_DATE) AS CHAR)

    I want to change the tank to the date format.

    Please help me,

    Thanks in advance,

    A.Kavya.

    Below him is based on my date format NLS source Oracle database as DD-MON-RR (query on the database - SELECT * > OF nls_database_parameters WHERE the PARAMETER = "NLS_DATE_FORMAT").

    Note that this is not altered by the connection of the RPD pool, which is common.

    If the date that I put together for substrings and Casts a match before it can be LAUNCHED as a DATE. IE 31 July 15 etc.

    Steps to follow:

    -Drag a field to the report, one

    -Change the formula

    -Paste in

    CAST ("31 - Jul -" |) SUBSTRING (CAST ('F_PL_BAL'. ' BUSINESS_DATE ' AS CHAR) FROM 8 TO 2) AS DATE).

    -OK

    -See the results

  • Convert the AM/PM chain to the legit Date format AM/PM

    Hello

    I would like to convert a string field, including a date (2014-02-11 07:13:14) in a legitimate date using the attribute 'string to date. ' Unfortunately, I can't turn these.

    I tried to add a new date format to the standard list.

    YYYY-MM-DD hh: mm: tt

    However, above was not accepted, and all dates cannot be converted.

    Thanks in advance for you help on this topic

    Hello

    Try to use the format string:

    YYYY-MM-DD hh: mm: one

    Kind regards

    Nick

Maybe you are looking for