RE: Oracle DATE data format conversion..

<C.M> Motta's question about dates and oracle>
Dealing with dates and Oracle is somewhat of a nuisance. Oracle is very
particular about how date strings are formatted, and if you get it wrong,
you get the (unhelpful) message that C.M. Motta showed us. However, if
you pass a DateTimeData to Oracle, Forte' does the right formatting for you.
If you do need to format the date prior to interacting with Oracle, use the
following format:
dd-mmm-yy <time component>
You can change the default format, but it is not easy.
If you customise Express generated code that interacts with an Oracle
database, again, make sure that you pass a DateTimeData, and not the
.TextValue.
Good luck!
Richard Kirk

Date: Wed, 06 Nov 1996 08:18:37 -0500
To: "C. M. Motta" <[email protected]>
From: Jim Milbery <[email protected]>
Subject: Re: Oracle DATE data format conversion..
Cc: [email protected]
Cheers:
Most likely what is happening is that you are using the default date
format of Oracle, and you are sending a four-character year. As follows:
SQL> insert into jimbo values ('01-dec-1997')
2 /
insert into jimbo values ('01-dec-1997')
ERROR at line 1:
ORA-01830: date format picture ends before converting entire inputstring
>
Oracle defaults to a format of 'dd-MON-yy'
You can either truncate the year, or manipulate the date to match the standard
database as follows:
insert into jimbo values (to_Date('01-jan-1997', 'DD-MON-YYYY'))
\jimbo
At 09:21 AM 11/6/96 -0200, you wrote:
Forte Users,
First, Id like to thank all those who answered my question on
droplist & SQL. I got just what I was looking for: its up and runnunig
now.
I have another question: Im trying to insert a DATE into an Oracle
database. The source date is:
data : DateTimeData = new;
data.SetCurrent();
So, when I try to insert data.Value or data.textvalue into DB, I
get the following exception:
ORA-01830: date format picture ends before converting entire
input string.
Are there any suggestions?
Thanks for your help,
C.M. Motta
====================================================================
Jim Milbery
Milbery Consulting Group
132 N. West St., Allentown, PA 18102
O: 610 - 432 - 5350 F: 610 - 432 - 5380
E-Mail : [email protected]
====================================================================

Similar Messages

  • Date format conversation in OBIEE

    Hello guys
    I am a quick question about how to stop OBIEE from using to_date conversation? The date format in the db is dd/month/yy, and when I run any report in OBIEE answer using Date columns, it will always convert the format to "dd/mm/YYYY". The sql generated will always have a to_date() in where clause..
    Is there a way to not have OBIEE does that and just show the date with format as it is and drop the to_date conversion in SQL?
    Thanks

    I think you are getting confused here. Oracle's default date format is dd-mon-yyyy. So when you run a query like this:
    DATE_COLUMN = '01-Nov-2009'
    Oracle applies an IMPLICIT data type conversion to your date string and converts it to a date data type. Whether you allow Oracle to do the implicit conversion or do it explicitly like this DATE_COLUMN = To_date('01-Nov-2009', 'dd-mon-yyyy') should always result in the same query performance. When to TO_DATE functions affect query performance? When you apply the function over the DATE_COLUMN like this:
    TO_DATE(DATE_COLUMN, 'dd-mon-yyyy') = '01-Nov-2009'
    Why? Because indexes on DATE_COLUMN WILL NOT be used unless you have defined a function level index with a index column using the function: TO_DATE(DATE_COLUMN, 'dd-mon-yyyy'). My guess is that your DATE_COLUMN is not a date but a varchar2, therefore when you pass in To_date('01-Nov-2009', 'dd-mon-yyyy') Oracle does an IMPLICIT conversion of your DATE_COLUMN to DATE data type to match the data type of your where condition hence it is taking long to execute as no indexes are used. Can you confirm what is the exact data type of the DATE_COLUMN you are using to filter on? Do you have an index defined in that column? Can you confirm exactly how is the index is defined? Have you ran statistics on the table AND the indexes as well?

  • Regarding Date Format Conversion

    Hi,
    In my project i am picking the date from the date picker which is a javascript program . Then i am displaying it on a jsp page .It is coming in mm/dd/yyyy format .I have to change it to dd/mm/yyyy format .
    I have the code for date formatting conversion .
    What my doubt is whether  the code should be written inside the jsp page or in the javascript .
    Thanks .

    Hi
    <%@page language="java" import="java.sql.*,java.util.*,java.text.*" %>
    <%SimpleDateFormat sdf= new SimpleDateFormat(dd/mm/yyyy );%>
    <% java.util.Date temp_date = sdf.parse(PassYourDateHere); %>
    use this with your jsp
    Regards
    Abhijith YS

  • Date format conversion issue in BW

    Hi Experts,
    I have 2 custom date fields for which I'm getting the values from oracle database through DB Connect in MM/DD/YYYY format (e.g values 10/20/2007 and 3/5/2007). But I want to convert this date format into SAP BW internal format (YYYYMMDD). I've defined the above 2 date fields in BW with a data type DATS (8 digits length) and wrote a code in the TRs as below. Both these fields are defined as a character with a length of 10 in the oracle system.
    data zresult(10) type C.
    data :  lv_day(2) type c,
    lv_month(2) type c,
    lv_year(4) type c.
    zresult =  tran_structure-spring_norm_date.
    lv_day = zresult+3(2).
    lv_month = zresult+0(2).
    lv_year = zresult+6(4).
    CONCATENATE lv_year lv_month lv_day into result.
    But still the data load is getting failed due to wrong date format and error in the routine. It says the value for the characteristic 0DATE doesn't have 8 spaces. Is there anything wrong with the routine?
    Could someone please share some inputs on this.
    Thanks,
    Krish

    Hi Narasimha,
    Thanks a lot for your prompt response and inputs. I used this code as below in my TR for the date field. But its still giving an error message saying "Value '20072109' of characteristic 0DATE is not possible and error when assigning SID". The value what I can see in the source system (oracle table) and in PSA for this record is '9/21/2007'. Am I still missing something here?
    DATA: get_date TYPE sy-datum,
    s1(2) TYPE c,
    s2(2) TYPE c,
    s3(4) TYPE c,
    lv_length TYPE i,
    lv_length1 TYPE i.
    SPLIT TRAN_STRUCTURE-FALL_NORM_DATE AT '/' INTO s1 s2 s3.
    lv_length = STRLEN( s1 ).
    IF lv_length = 1.
    CONCATENATE '0' s1 INTO s1.
    ENDIF.
    lv_length1 = STRLEN( s2 ).
    IF lv_length1 = 1.
    CONCATENATE '0' s2 INTO s2.
    ENDIF.
    CONCATENATE s3 s2 s1 INTO get_date.
    RESULT = get_date.
    Could you please help me on this?
    FYI, I have defined my date field in ODS with the data type DATS in order to display the output in YYYYMMDD format.
    Thanks,
    Krish

  • I have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion

    i have proubleam with string to date conversion, i out put date fromat is 2012-04-30T23:48:55.727-07:00 . so please help me the format conversion.
    i wrote the method but it not workig
    My method is
    -(NSDate *)dateformstr:(NSString *)str
    NSString *date = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSDateFormatter *dateFormate = [[NSDateFormatter alloc] init];
      [dateFormate setDateFormat:@"yyyy-MM-dd'T'HH:mm:sssZZZZ"]
    // NSDate *formatterDate = [dateFormate  dateFromString:str];
        return formatterDate;
    but i did not the value and if i try othere formate i is working but my requiremet format is 2012-04-30T23:48:55.727-07:00.
    can any help it out in this senario.

    Sorry Butterbean, but I'm interested in the answer to your question myself.
    I've spent a few hours transfering my library from one computer to another and then find out that my ratings didn't transfer. Like you, I've spent many hours rating my 2000+ songs. I'm sure you have more, nevertheless, I want to find out how to get those ratings. They still show in my iTunes on my laptop but, when I go to the iTunes folder and display the details of at song, no rating is there. If you find out how to get them to display there in the iTunes folder, it seems that would be the key.
    Hope you get your answer soon.

  • (RR FORMAT) ORACLE의  2000년대 DATE FORMAT

    제품 : SQL*PLUS
    작성날짜 : 1997-04-23
    (RR FORMAT) ORACLE의 2000년대 DATE FORMAT
    ==========================================
    이 문서는 단지 정보 제공을 목적으로 하며 여기에 있는 내용은 통보 없이 변경될
    수 있습니다. 오라클은 이 문서에 오류가 없다는 것을 보증하지 않으며, 특정 목
    적에 부합하거나 혹은 상업성에 대한 묵시적인 보증과 조건 -구두적으로 표현되었
    거나 법적으로 함축되었거나- 을 포함하는 어떠한 보장도 제공하지 않습니다. 오라
    클은 본 문서와 관련하여 어떠한 법률적 책임도 지지 않으며, 직접 또는 간접적으
    로 어떠한 계약적 의무도 형성되지 않습니다. 본 문서는 오라클의 사전 서면 동의
    없이 어떠한 목적으로도 전자적으로나 기계적으로 재작성되거나 다른 형태로 변경
    될 수 없습니다.
    ORACLE 7은 세기의 전환에 대해 'RR' 이라는 새로운 DATE FORMAT을 제공한다.
    'RR' 은 DATE FORMAT의 마지막 2 DIGITS에 다른 세기에 대한 DATE값을 저장한다는
    것을 제외하고는 'YY' FORMAT과 유사하다.
    다음은 사용자가 지정하는 YEAR를 현재의 YEAR를 기반으로 하여,
    'RR' FORMAT이 RETURN하는 DATE(세기)를 나타낸 것이다.
    현재 YEAR의 지정된 YEAR의 'RR' FORMAT결과
    마지막 2 DIGIT     마지막 2 DIGIT
    0 - 49     0 - 49     현재 세기
    50 - 99      0 - 49 다음 세기
    0 - 49      50 - 99     이전 세기
    50 - 99     50 - 99     현재 세기
    예를 들면, 현재가 1993년이면, 50에서 90사이의 년도는 20세기에 포함되고,
    0에서 49사이의 년도는 21세기에 포함된다. 마찬가지로 현재가 2001년이면
    50에서 90사이의 년도는 20세기에 포함되고, 0에서 49사이의 년도는 21세기에
    포함된다.
    다음은 'RR'사용에 대한 예이다.
    이와 같이 RR type을 사용하여 모든 application을 수정하기 곤란할 때에는
    환경변수의 nls_date_format을 변경하여도 된다.
    단, nls_date_format은 이후에 다른 사용자에 의해 변경되어질 수도 있으므로
    application을 수정하는 것이 안전하다.
    SQL> INSERT INTO EMP(empno, deptno, hiredate)
    VALUES(9999, 20, TO_DATE('01-JAN-03', 'DD-MON-RR'));
    1 row created.
    SQL> INSERT INTO EMP(empno, deptno, hiredate)
    VALUES(8888, 20, TO_DATE('01-JAN-67', 'DD-MON-RR'));
    1 row created.
    SQL> SELECT empno, deptno, TO_CHAR(hiredate, 'DD-MON-YYYY') hiredate
    FROM EMP;
    EMPNO DEPTNO HIREDATE
    8888 20 01-JAN-1967
    9999 20 01-JAN-2003

    RR was introduced as a Y2K workaround for all those programs that didn't store the century. It has a fixed window - 50 to 99 defaults to twentieth century, 00 to 49 is twenty-first. YY on teh other hand just defaults to the current century. At least in 9.2 it does. I think in earlier version of the database it defaulted to 00 - hence many systems apparently have records that were created in the first century AD.
    SQL> SELECT to_char(to_date('01-JAN-50', 'DD-MON-RR'), 'DD-MON-YYYY')
      2  FROM  dual
      3  /
    TO_CHAR(TO_
    01-JAN-1950
    SQL> SELECT to_char(to_date('01-JAN-49', 'DD-MON-RR'), 'DD-MON-YYYY')
      2  FROM  dual
      3  /
    TO_CHAR(TO_
    01-JAN-2049
    SQL> SELECT to_char(to_date('01-JAN-50', 'DD-MON-YY'), 'DD-MON-YYYY')
      2  FROM  dual
      3  /
    TO_CHAR(TO_
    01-JAN-2050
    SQL> SELECT to_char(to_date('01-JAN-49', 'DD-MON-YY'), 'DD-MON-YYYY')
      2  FROM  dual
      3  /
    TO_CHAR(TO_
    01-JAN-2049
    SQL> Cheers, APC

  • DATE vs DATETIME conversion

    I am running into a strange issue which is preventing me to finish my project. Any help would be greatly appreciated. 
    It looks like the CONVERT (the same goes for CAST) function treats DATE and DATETIME conversions differently when executed by a user with the Dutch language settings.
    Here is what I mean, I run the following query:
    SELECT CONVERT(DATE, '2014-09-01 23:00:00'), CONVERT(DATETIME, '2014-09-01 23:00:00')
    The results are:
    2014-09-01, 2014-01-09 23:00:00
    The conversion to DATETIME swapped the month and the day around, while this doesn't happen for the DATE conversion. The DATE conversion is the correct format, since I supplied it YYYY-MM-DD HH:mm:ss.
    When I run the same query using a user with the default language settings (en-US I assume) the same query works fine (no swapping of month and day values). 
    Can someone explain why this is happening? And maybe more important how to prevent it or workaround it (changing the language for the user from Dutch to default is not an option)? 
     

    >> Can someone explain why this is happening? And maybe more important how to prevent it or workaround it (changing the language for the user from Dutch to default is not an option)? <<
    CONVERT() is an old Sybase string function. It was created to keep 960's COBOL programmers happy since SQL does not have a PICTURE clause to put data in display formats. 
    CAST() is the ANSI/ISO Standard function to convert data types and this is what you should be using. It is not a string function. It uses the ISO-8601 standard for dates (yyyy-mm-dd), as you have seen. This is the only -– repeat, only! -- format allowed in
    SQL. Microsoft is a few decades behind and trying to catch up now.
    A good SQL programmer will do any local display formatting in the presentation, which will handle local languages that are never used in the database. Want to have some fun? The names of months in Polish, Czech, Croatian, Ukrainian and Belarusian not based
    on the Latin names used in most European languages. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to convert JAVA.SQL.DATE date in YYYY/MM/DD format into DD/MM/YYYY

    i am using informix database which accepts date value in the form of DATE format......
    the other part of my application takes date from the field in DD/MM/YYYY format...so i have to convert my java.sql.date in YYYY/MM/DD fromat into DD/MM/YYYY fromat of same type before inserting into db......
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........

    816399 wrote:
    i am using informix database which accepts date value in the form of DATE format......Huh?
    Maybe you mean Informix (fronted by JDBC) expects date values as java.sql.Date objects?
    the other part of my application takes date from the field in DD/MM/YYYY format...
    so i have to convert my java.sql.date in YYYY/MM/DD format into DD/MM/YYYY format of same type before inserting into db......I am not sure why you are talking about formats here.
    There is no formatting inherent in a java.util.Date object
    nor in a java.sql.Date object.
    but using parse method in SimpleDateFormat class can get the result only in java.util.date format...
    and also using format method can result only in string conversion........You can easily create a java.sql.Date object from a java.util.Date object.
    String s = "31/12/2010";
    java.util.Date ud = new java.text.SimpleDateFormat("dd/MM/yyyy").parse(s);
    java.sql.Date sd = new java.sql.Date(ud.getTime());
    ud = sd; // java.sql.Date extends java.util.Date so no conversion is needed

  • ANSI X12 meta data availability in conversion agent??

    Hello,
    Is there a provision for availability of ANSI X12 meta data in SAP conversion agent. We are trying to process EDI orders using the X12 INDUSTRY standard. Please advise.
    -Kris

    hi,
    SAP Conversion Agent together with SAP Net Weaver, enables  to automate complex integration activities for a multitude of data and document formats. These include unstructured and partially structured documents such as Office files, data streams, printing applications, and other application-specific formats.
    Easily integrate unstructured and semi-structured data into SAP Net  Weaver Process Integration using the Conversion Agent.
    Conversion Agent dynamically converts unstructured messages from   Microsoft Word,Excel,PDF plain text. 
    Semi-structured formats such as HL7,SWIFT,HIPA, ANSI X12 and COBOL to   PI understandable SOAP XML.
              So that it helps to easily integrate the information need into the back-end systems. Conversion can also be used as the reverse process to convert from XML to unstructured or semi-structured formats
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/sap%2bconversion%2bagent%2b-%2bthe%2blong%2bjourney
    Conversion Agent - Handling EDI termination characters
    Conversion Agent a Free Lunch?
    Integrate SAP Conversion Agent by Itemfield with SAP XI
    regards
    sr

  • Browser date field format in header

    I am using Browser 2.0 for some ad hoc queries on an Oracle
    7.2.3 database.
    My client is running Windows NT 4.0 with Service Pack 4.
    Regional settings are set to English (Australia).
    The page setup in Browser allows you in the header or footer to
    insert the a date field via "&d". Documentation states this is
    system generated.
    However, in the print preview and print out the date is
    formatted as MM/DD/YY. I need to have it formatted as DD-MON-
    YYYY.
    Can anyone suggest to me from which system the format is being
    generated or any
    suggestions on how to change it in.
    Thanks
    null

    can you paste the timestamp being displayed?
    You can use, format-date function or other, but its all based on the data you have for DATE.

  • Oracle 11g - Date Issue?

    Oracle 11g - Date Issue?
    =====================
    I hope this is the right forum for this issue, if not let me, where to go.
    We are using Oracle 11g (11.2.0.1.0) on (Platform : solaris[tm] oe (64-bit)), Sql Developer 3.0.04.
    Our NLS_DATE_FORMAT = 'DD-MON-RR'
    Using 'RR' in the format forces two-digit years less than or equal to 49 to be interpreted as years in the 21st century (2000–2049), and years 50 and over, as years in the 20th century (1950–1999). Setting the RR format as the default for all two-digit year entries allows you to become year-2000 compliant. For example:
    We have a date '01-JUN-31' in our source system. It treat this date as 01-JUN-2031' instead of '01-JUN-1931'. One century forward.
    Do we able to resolve using NLS_DATE_FORMAT change?
    How do we resolve this issue?
    Thanks in helping.

    qwe16235 wrote:
    Our source is Oracle data base, where S_date is defined as DATE. Why did you say STRING , when it defined as DATE data type?I doubt you source is an Oracle database. You may have it stored in an Oracle database, but it cam form somewhere else, and was very likely inserted into the table as a string, wherever it came from. Given a string that resembles a date, Oracle will try to convert it to a date using the nls_date_format parameter for the session (which can either be set in the session or inherited form the database). Perhaps this will help explain:
    SQL> create table t (conv_type varchar2(10), dt date);
    Table created.
    SQL> alter session set nls_date_format = 'dd-mon-rr';
    Session altered.
    SQL> insert into t values ('Implicit', '01-jun-31');
    1 row created.
    SQL> insert into t values ('Explicit', to_date('01-jun-1931', 'dd-mon-yyyy'));
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select conv_type, to_char(dt, 'dd-mon-yyyy') dt
      2  from t;
    CONV_TYPE  DT
    Implicit   01-jun-2031
    Explicit   01-jun-1931So, unless you are really inserting dates, not strings that look like dates, you are going to have problems.
    John

  • Custom date validation format for dff field

    requirement -
    dff has a specific date time format different from the standard valuesets for date-time stamp available in apps. So if the user enters the incorrect format, it should do the validation.
    Format needed for dff is : 2012-04-30 15:46:35
    I tried a couple of thigs but dint fork . How do I do it.
    any suggestions ?
    Thnks

    This topic was discussed many times in the forum before, please see old threads for details.
    https://forums.oracle.com/forums/search.jspa?threadID=&q=dff+AND+Validation&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=dff+AND+Validate&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=dff+AND+Validation+AND+Personalization&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • SQL * Loader : Load data with format MM/DD/YYYY HH:MI:SS PM

    Please advice how to load data with format MM/DD/YYYY HH:MI:SS PM into an Oracle Table using SQL * Loader.
    - What format should I give in the control file?
    - What would be the column type to create the table to load data.
    Sample data below;
    MM/DD/YYYY HH:MI:SS PM
    12/9/2012 2:40:20 PM
    11/29/2011 11:23:12 AM
    Thanks in advance
    Avinash

    Hello Srini,
    I had tried with the creation date as DATE datatype but i had got an error as
    ORA-01830: date format picture ends before converting entire input stringI am running the SQL*LOADER from Oracle R12 EBS front-end.
    the contents of my control file is
    LOAD DATA
    INFILE "$_FileName"
    REPLACE
    INTO TABLE po_recp_int_lines_stg
    WHEN (01) = 'L'
    FIELDS TERMINATED BY "|"
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    INDICATOR                POSITION(1) CHAR,
    TRANSACTION_MODE          "TRIM(:TRANSACTION_MODE)",
    RECEIPT_NUMBER               "TRIM(:RECEIPT_NUMBER)",
    INTERFACE_SOURCE          "TRIM(:INTERFACE_SOURCE)",
    RECEIPT_DATE               "TO_CHAR(TO_DATE(:RECEIPT_DATE,'MM/DD/YYYY'),'DD-MON-YYYY')",
    QUANTITY               "TRIM(:QUANTITY)",
    PO_NUMBER               "TRIM(:PO_NUMBER)",
    PO_LINE_NUMBER               "TRIM(:PO_LINE_NUMBER)",
    CREATION_DATE               "TO_CHAR(TO_DATE(:CREATION_DATE,'MM/DD/YYYY HH:MI:SS AM'),'DD-MON-YYYY HH:MI:SS AM')",
    ERROR_MESSAGE                   "TRIM(:ERROR_MESSAGE)",
    PROCESS_FLAG                    CONSTANT 'N',
    CREATED_BY                      "fnd_global.user_id",
    LAST_UPDATE_DATE                SYSDATE,
    LAST_UPDATED_BY                 "fnd_global.user_id"
    {code}
    My data file goes like
    {code}
    H|CREATE|123|ABC|12/10/2012||||
    L|CREATE|123|ABC|12/10/2012|100|PO12345|1|12/9/2012  2:40:20 PM
    L|CORRECT|123|ABC|12/10/2012|150|PO12346|2|11/29/2011 11:23:12 AM{code}
    Below is the desc of the table
    {code}
    INDICATOR             VARCHAR2 (1 Byte)                         
    TRANSACTION_MODE        VARCHAR2 (10 Byte)                         
    RECEIPT_NUMBER             NUMBER                         
    INTERFACE_SOURCE        VARCHAR2 (20 Byte)                         
    RECEIPT_DATE             DATE                    
    QUANTITY             NUMBER                    
    PO_NUMBER             VARCHAR2 (15 Byte)                         
    PO_LINE_NUMBER             NUMBER                         
    CREATION_DATE             TIMESTAMP(0)                         
    ERROR_MESSAGE             VARCHAR2 (4000 Byte)                         
    PROCESS_FLAG             VARCHAR2 (5 Byte)                         
    CREATED_BY             NUMBER               
    LAST_UPDATE_DATE        DATE               
    LAST_UPDATED_BY             NUMBER     {code}
    Thanks,
    Avinash                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Determine Date field format dynamically

    Hello friends,
    I'm writing some database access code in java. The biggest problem I face is date fields. Because I don't know the date field format (For example, in SQL Sever we can have dd/mm/yy or mm/dd/yy, etc), I can't format dates for insert/update statements.
    Is there a way to determine the date field format dynamically? Regardless of database, for ex. MS SQL, Oracle?
    Thank you.

    Hey!
    There is a way to do this! The Oracle Database understands SQL92 Syntax. So you can use
    - {d ?yyyy-mm-dd?} for date representation,
    - {t ?hh:mm:ss?} for time representation,
    - {ts ?yyyy-mm-dd hh:mm:ss.f...?} for timestamp rep.
    Here is a small example:
    // Connect to the database
    // You can put a database name after the @ sign in the connection URL.
    Connection conn = DriverManager.getConnection
    ("jdbc:oracle:oci8:@", "scott", "tiger");
    // Create a Statement
    Statement stmt = conn.createStatement ();
    // Select the ename column from the emp table where the hiredate is Jan-23-1982
    ResultSet rset = stmt.executeQuery
    ("SELECT ename FROM emp WHERE hiredate = {d ?1982-01-23?}");
    // Iterate through the result and print the employee names
    while (rset.next ())
    System.out.println (rset.getString (1));I hope this is what you wanted to know!

  • ORA-01820: format code cannot appear in date input format

    I don't understand why I am getting the error below. That should be valid, no?
    TIA for any insight.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    SQL>
    SQL> select to_date('2004 01 3','yyyy mm w') from dual;
    select to_date('2004 01 3','yyyy mm w') from dual
    ERROR at line 1:
    ORA-01820: format code cannot appear in date input format
    SQL>
    SQL> select to_char(sysdate,'yyyy mm w') from dual;
    TO_CHAR(S
    2008 08 1

    LC,
    ORA-01820:     format code cannot appear in date input format
    Cause:     A date specification contained an invalid format code. Only the following may be specified when entering a date: year, month, day, hours, minutes, seconds, Julian day, A.M./P.M. and B.C./A.D.
    Action:     Remove the invalid format code from the date specification.
    Looking at the cause,you can't use a format code like W in the date format for converting a text to date. To_date doesn't accept it.
    Aman....

Maybe you are looking for