How to parse string to date with defualt format?

is there any possibilities to parse a string to date if we don't specify the format in SDF?
In database we have different formats and we need to convert each one convert to date with common format(something like default), is there any possibilities to do in java?

jwenting wrote:
Tolls wrote:
ColinAtWork wrote:
SumantK wrote:
In database we have different formats and we need to convert each one convert to date with common format(something like default), is there any possibilities to do in java?Why don't you store the date in the database as a DATE datatype then you can format anyway you like??Because some people seem to fear DATEs and prefer the supposed comforts of a VARCHAR2...after all, who knows what murky goings on occur with a DATE, but at least a VARCHAR2 is readable, or something like that anyway.Just because some people don't know how to work with DATE fields (which is the real reason for their "fear" doesn't mean you shouldn't use them.
They're the appopriate solution, so use it.Often but not always true.
For example neither MS SQL Server nor Oracle timestamp types will store the resolution capable with the Java Date type. So if one wants to maintain all of that resolution one requires either a varchar or two columns.
And although I haven't been able to confirm it (recently at least) at one time one of the Oracle drivers had a bug that a timestamp would wipe out following columns. For that one either one was left with having only a single timestamp as the last column or using a varchar.

Similar Messages

  • How to parse string to date in j2me?

    How to parse string to date in j2me?
    Please help me.

    Hi..
    String dyStr = "20";
    String mtStr = "1";
    String yrStr = "1999";
    Calendar cal = Calendar.getIntstance();
    int dy = Integer.parseInt(dyStr);
    int mt = Integer.parseInt(mtStr);
    int yr = Integer.parseInt(yrStr);
    cal.set(Calendar.DATE, dy);
    cal.set(Calendar.MONTH, mt);
    cal.set(Calendar.YEAR, yr);
    OK?

  • How to parse thus XML data?

    Hi,experts:
    In below thread:
    Receiving .Net dataset with deployed proxies
    i asked how to create a external definition in IR base on above XML data.
    Now,i have created a XSD file base on the XML data.And importing it into IR successfully.
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="Status">
    <xs:complexType>
    <xs:attribute name="Result" type="xs:string"/>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    And now,the question is how to parse the XML data in diffgr:diffgram  segment.It seems a MS-XML syntax.Can it be parsed by XI?
    I tried,but the following error occurs:
    com.sap.aii.utilxi.misc.api.BaseRuntimeException: RuntimeException in Message-Mapping transformation: Cannot produce target element /ns0:ZMT_SD_ORDER01_RESULT. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at com.sap.aii.mappingtool.tf3.AMappingProgram.start

    Hi,
    The above Exception seems to be because of mapping error.
    Check your mapping for all the mandatory 1-1 mapping, also the 1-unbounded parent node mapping.
    Once when you import the XSD and activate your External Definition if it does without any error then there is no problem with your External Definition.
    If this error occurs only when you test your mapping then this is mapping error and not because of XSD.
    Please check the parent node mapping like 1-unbounded.
    Reward Points if useful
    Regards
    Ashmi.

  • How to export string in CDATA with the jaxb xml writer?

    How to export string in CDATA with the jaxb xml writer?
    It read CDATA no problem but it is lost on write.

    Found it:
    ### THIS WORKS WITH SUN JAXB REFERENCE IMPLEMENTATION. ###
    (Not tested with any other)
    In the xsd, you must create a type for your string-like element.
    Then associate a data type converter class to this new type, which will produce CDATA tags.
    Then you must set a custom characterEscapeHandler to avoid the default xml escaping in order to preserve the previously produced CDATA tag.
    Good luck.
    -----type converter-----
    import javax.xml.bind.DatatypeConverter;
    public class ExpressionConverter {
         * Convert an expression from an XML file into an internal representation. JAXB will
         * probably have already stripped off the CDATA encapsulation. As a result, this method
         * simply invokes the JAXB type conversion for strings but does not take any other action.
         * @param text an XML-compliant expression
         * @return a pure string expression
         public static String parse(String text) {
              String result = DatatypeConverter.parseString(text);
              return result;
         * Convert an expression from its internal representation to an XML-compliant version.
         * This method will simply surround the string in a CDATA block and return the result.
         * @param text a pure string expression
         * @return the expression encapsulated within a CDATA block
         public static String print(String text) {
              StringBuffer sb = new StringBuffer(text.length() + 20); //should add the length of the CDATA tags + 8 EOLs to be safe
              sb.append("<![CDATA[");
              sb.append(wrapLines(text, 80));
              sb.append("]]>");
              return DatatypeConverter.printString(sb.toString());
         * Provides line-wrapping for long text strings. EOL indicators are inserted at
         * word boundaries once a specified line-length has been exceeded.
         * @param text the string to be wrapped
         * @param lineLength the maximum number of characters that should be included in a single line
         * @return the new string with appropriate EOL insertions
         private static String wrapLines(String text, int lineLength) {
              //wrap logic, watchout for quoted strings!!!!
              return text;
    ------in caller----
    Marshaller writer = ......
    writer.setProperty("com.sun.xml.bind.characterEscapeHandler", new NoCharacterEscapeHandler());
    -----escaper-----
    import java.io.IOException;
    import java.io.Writer;
    import com.sun.xml.bind.marshaller.CharacterEscapeHandler;
    public class NoCharacterEscapeHandler implements CharacterEscapeHandler {
         * Escape characters inside the buffer and send the output to the writer.
         * @param buf buffer of characters to be encoded
         * @param start the index position of the first character that should be encoded
         * @param len the number of characters that should be encoded
         * @param isAttValue true, if the buffer represents an XML tag attribute
         * @param out the output stream
         * @throws IOException if the writing process fails
         public void escape(char[] buf, int start, int len, boolean isAttValue, Writer out) throws IOException {
              for (int i = start; i < start + len; i++) {
                   char ch = buf;
                   if (isAttValue) {
                        // isAttValue is set to true when the marshaller is processing
                        // attribute values. Inside attribute values, there are more
                        // things you need to escape, usually.
                        if (ch == '&') {
                             out.write("&");
                        } else if (ch == '>') {
                             out.write(">");
                        } else if (ch == '<') {
                             out.write("<");
                        } else if (ch == '"') {
                             out.write(""");
                        } else if (ch == '\'') {
                             out.write("&apos;");
                        } else if (ch > 0x7F) {
                             // escape everything above ASCII to &#xXXXX;
                             out.write("&#x");
                             out.write(Integer.toHexString(ch));
                             out.write(";");
                        } else {
                             out.write(ch);
                   } else {
                        out.write(ch);
              return;

  • How to calculate any two date with diffence calculation by using obiee11g?

    Hi,
    i have a requirement like,
    location wise current month and previous month with movement calculation,can to tell me how to calculate any two date with diffence calculation
    by using obiee11g
    Note,
    I tried to implemented ago function as well as dynamic two dates calculation using $2-$1 methods..but i am getting the o/p it's self i am getiing some null value also that' why it's not tallying with our actual report.
    i tired to used ifnull(mesaurecolumn,0) also case condition on the mesaure colution still it's not tallying.
    THanks and Rds,
    Devarasu.R

    Hi,
    for Date Difference........
    TimestampDiff(interval, timestamp1, timestamp2)
    ex:TimestampDiff(SQL_TSI_DAY, cast('1-apr-2011' as date), current_date)
    Where:
    interval
    The specified interval. Valid values are: SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY,
    SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, SQL_TSI_YEAR.
    Cheers,
    Aravind

  • How i map the caf data with data of UWL in web dynpro

    Hi Experts,
    i created a bpm project with nwce 7.1.1 and it have a independent caf to keep it's data and status.
    now i have to create a view(use web dynpro) such like UWL,
    my question is
    how i map the caf data with UWL, and let the view can open the task(popup a window, just like UWL do) for user to finish their job?
    thanks.

    Hi Vic
    Your requirement is exect functionality of UWL based on WEBDYNPRO, CAF and BPM for automation? ,and question is How to use CAF with WD or CAF with UWL API's ?. please clarify it.
    Please fo through from given doc misght give u some idea
    1. [How to develop Web Dynpro UI for your CAF project |http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417300)ID0722080650DB02400261803144436507End?blog=/pub/wlg/5414]
    Best Regards
    Satish Kumar

  • How can I  get System dates  with time scheduler using threads

    how can I get System dates with time scheduler using threads.is there any idea to update Date in my application along with system Date automatic updation...

    What the heck are you talking about and whatr has it to do with threads?
    Current time: System.currentTimeMillis. Date instances are not supposed to be updated.

  • How to write the oracle data as XML format. (.XML file)

    create or replace procedure pro(p_number )
    is
    cursor c1 is select *from emp where empno=p_number;
    v_file utl_file.file_type;
    begin
    v_file := utl_file.fopen('dirc','filename.txt','w');
    for i in c1 loop
    utl_file.put_line(v_file,i.ename || i.empno ||i.job);
    end loop;
    closef(v_file);
    end;
    Now my client want instead of .txt file he need .xml files
    File should contains xml tags. can any one help regarding this.. with one example.
    How to write the oracle data as XML format. (.XML file)

    hi,
    hope this example will do something....
    SQL> select employee_id, first_name, last_name, phone_number
    2 from employees where rownum < 6
    EMPLOYEE_ID FIRST_NAME LAST_NAME PHONE_NUMBER
    100 Steven King 515.123.4567
    101 Neena Kochhar 515.123.4568
    102 Lex De Haan 515.123.4569
    103 Alexander Hunold 590.423.4567
    104 Bruce Ernst 590.423.4568
    SQL> select dbms_xmlgen.getxml('select employee_id, first_name,
    2 last_name, phone_number from employees where rownum < 6') xml
    3 from dual;
    *<?xml version="1.0"?>*
    *<ROWSET>*
    *<ROW>*
    *<EMPLOYEE_ID>100</EMPLOYEE_ID>*
    *<FIRST_NAME>Steven</FIRST_NAME>*
    *<LAST_NAME>King</LAST_NAME>*
    *<PHONE_NUMBER>515.123.4567</PHONE_NUMBER>*
    *</ROW>*
    *<ROW>*
    *<EMPLOYEE_ID>101</EMPLOYEE_ID>*
    *<FIRST_NAME>Neena</FIRST_NAME>*
    *<LAST_NAME>Kochhar</LAST_NAME>*
    *<PHONE_NUMBER>515.123.4568</PHONE_NUMBER>*
    *</ROW>*
    *<ROW>*
    *<EMPLOYEE_ID>102</EMPLOYEE_ID>*
    *<FIRST_NAME>Lex</FIRST_NAME>*
    *<LAST_NAME>De Haan</LAST_NAME>*
    *<PHONE_NUMBER>515.123.4569</PHONE_NUMBER>*
    *</ROW>*
    *<ROW>*
    *<EMPLOYEE_ID>103</EMPLOYEE_ID>*
    *<FIRST_NAME>Alexander</FIRST_NAME>*
    *<LAST_NAME>Hunold</LAST_NAME>*
    *<PHONE_NUMBER>590.423.4567</PHONE_NUMBER>*
    *</ROW>*
    *<ROW>*
    *<EMPLOYEE_ID>104</EMPLOYEE_ID>*
    *<FIRST_NAME>Bruce</FIRST_NAME>*
    *<LAST_NAME>Ernst</LAST_NAME>*
    *<PHONE_NUMBER>590.423.4568</PHONE_NUMBER>*
    *</ROW>*
    *</ROWSET>*
    ask if you want more assistance.
    thanks.

  • How to convert internal table data to PDF format

    HI,
         I have an internal table data having one field with 255 chars. length.I want to send that intenal table data as attachemnt with external mail. i am thinking of converting that data into PDF format and use the FM to send the mail. How to convert internal table data to PDF format.
    Kishore

    In which format is your data in the internal table currently. Is it returned by a smartform/script or its just data fetched from some database table into an internal table. Since its obvious that the data should appear in the PDF with some Layout, you should be using smartform to format the data properly. See the Link
    Smartform to PDF to EMAIL
    This shows convertion of smartform to pdf and send it through email
    Regards,
    Abhishek

  • How can i save a data in text format

    how can i save a data in text format in labwindows cvi
    Message Edited by Tikoy on 04-14-2010 11:30 PM
    Solved!
    Go to Solution.

    Hi,
    If your data is in an array, the easiest way is to use the ArrayToFile function.
    It automatically creates a file and puts your data in it according to the format you provide.
    If you have individual samples that you need to write once in a while, you can either collect them into an array and then use ArrayToFile or open a file with fopen and write them as they are acquired with fwrite.
    Hope this helps, 
    S. Eren BALCI
    www.aselsan.com.tr

  • How to download the Dynamic data into PPT format

    Hi Friends,
    I have one doubt on WDJ. How to download the Dynamic data into PPT format. For Example Some Dynamic data is available in to View in that One Download Link or button available. Click on Download link or button download that data into PPT Format
    Is it possible for WDJ. If possible please tell me.
    Or
    How to create Business Graphics in Web Dynpro Applications depening up on Excel Data and finally we can download the  Business Graphics  into powerpoint presentation.
    Thank you,
    Regards
    Vijay Kalluri
    Edited by: KalluriVijay on Mar 11, 2011 6:34 AM

    Hi Govindu,
    1. I have one doubt on WDJ. Click on either Submit Buttion or LinkToURL UI we can download the file that file having ppt formate(Text.PPT).
    I am using NWDS Version: 7.0.09 and Java Version: JDK 1.6
    2. is it possible to download the business Graphics in to the PPT by using Java DynPro
    Regards
    VijayK

  • HT3775 how do you play a video with this format/title DVDSCR XViD AC3-sC0rp?

    How do you play a video with this format " DVDSCR XViD AC3-sC0rp" using quicktime?

    Try this. It can handle formats Quicktime can't:
    VLC

  • How to convert String to date ? - MS access

    I want to convert a string "10-10-08" [ MM-dd-yy ] into date type in same format to use that in query statement [MS Access].
    In table , I am using field called "date" with "MM-dd-yy" format.
    Example:
    <%@ page import= "java.sql.*"%>
    <%@ page import="java.text.SimpleDateFormat"%>
    <%@ page import="java.util.Date"%>
    <%
    String d="10-9-08";
         SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yy");
              Date date = dateFormat.parse(d);
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb");
         Statement st = con.createStatement();
    ResultSet rs=st.executeQuery("Select * from datacollectdb where date='"+date+"'");
    %>
    I am getting "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    " error.
    How to use the string "10-10-08" in where statement?

    sangee wrote:
    I want to convert a string "10-10-08" [ MM-dd-yy ] into date type in same format to use that in query statement [MS Access].
    In table , I am using field called "date" with "MM-dd-yy" format.I think a column named "date" is a very bad idea. Not just because "date" is a keyword. It's not very self-describing. How about "birth_date" or "hire_date" or "went_on_my_first_date"?
    Example:Scriptlets? There's your second mistake.
    <%@ page import= "java.sql.*"%>
    <%@ page import="java.text.SimpleDateFormat"%>
    <%@ page import="java.util.Date"%>
    <%
    String d="10-9-08";The way you're doing things, "2-40-99" is a valid date. Is that what you want?
         SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yy");
              Date date = dateFormat.parse(d);
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb");Wrong again. Better to use a PreparedStatement and bind that Date.
         Statement st = con.createStatement();
    ResultSet rs=st.executeQuery("Select * from datacollectdb where date='"+date+"'");
    %>
    I am getting "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    " error.
    How to use the string "10-10-08" in where statement?Use PreparedStatement and bind.
    Your JSP should not be getting a database connection. Pool it.
    Your code is wrong on every level. You don't close resources, you don't separate you app into layers, your database code is not in a POJO. I'd recommend that you throw this away and start again.
    %

  • Parsing String to date

    This is my function to convert a string into a desired output format.But my Date in the desired output format is coming out to be null.Could smeone plz point out my mistake.
    Date getDateInDesiredFormat(String strInputDate,String strInputFormat,String strOutputFormat)
         try
           SimpleDateFormat sdfInput  = new SimpleDateFormat(strInputFormat);
           SimpleDateFormat sdfOutput = new SimpleDateFormat("MM-dd-yyyy");
           ParsePosition pos = new ParsePosition(0);
           Date dtInputDate=sdfInput.parse(strInputDate.trim(),pos);
           System.out.println(dtInputDate);
           String strFormattedDate=sdfOutput.format(dtInputDate);
           System.out.println(strFormattedDate);
           Date dtOutputDate=sdfOutput.parse(strFormattedDate.trim(),pos);
           if(dtOutputDate==null)
                System.out.println("dtOutputDate is null ");
           else
               System.out.println(dtOutputDate.toString());
           return dtOutputDate;
         catch (NullPointerException npex)
             return null;
          catch(Exception ex)
              return null;
       }This is how i am calling the function
    Date date=getDateInDesiredFormat("Fri Sep 30 20:30:56 IST 2006","EE MMM d HH:mm:ss ZZZ yyyy","MM-dd-yyyy");
      }

    You need to use the sdfInput object to parse the date and sdfOutput to format and print it (like you did before your 'if'):
    SimpleDateFormat sdfInput  = new SimpleDateFormat(strInputFormat);
    SimpleDateFormat sdfOutput = new SimpleDateFormat("MM-dd-yyyy");
    Date dtInputDate=sdfInput.parse(strInputDate.trim());
    String strFormattedDate=sdfOutput.format(dtInputDate);
    System.out.println(strFormattedDate);the toString() you use in the else block uses a default format, not the one you specify.

  • How to convert string to date based on regional settings

    How can I convert a simple string ("01/04/2003" or "01-04-2003" or "01 April 2003") to a date formatted according to the regional settings?
    For example, if my regional settings is set to "dd mm yyyy", the result will be 01 as dd, 04 as mm and 2003 as yyyy.
    If the regional settings is set to "mm dd yyyy", the result will be 01 as mm, 04 as dd and 2003 as yyyy
    Hope someone can help.
    Thanks in advance.

    I think you have the wrong idea about how Oracle stores dates. Any date in Oracle is stored in a seven byte representation
    SQL> SELECT DUMP(last_hire_dt) FROM emp_t WHERE rownum = 1;
    DUMP(LAST_HIRE_DT)
    Typ=12 Len=7: 119,191,5,6,1,1,1This storage is independent of the NLS date settings. The TO_CHAR(dt,format) and TO_DATE(str,format) functions serve to translate this internal representation into the external presentation supplied by the format. So, if you need to translate a date that is contained in a string into an Oracle date datatype, you need to tell Oracle how to parse the string.
    If the string format matches your NLS_DATE_FORMAT parameter, Oracle will do this implicitly. Otherwise, you need to tell Oracle explicitly which piece is which. For example, is the string (ignoring the problem of two digit years :-) ):
    '02/01/03'
    Feb. 1, 2003, Jan. 2, 2003, or Mar. 1, 2002? If your date format is dd-MON-yyyy as mine is, then:
    SQL> SELECT TO_DATE('02/01/03') FROM dual;
    SELECT TO_DATE('02/01/03') FROM dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL> SELECT TO_DATE('30-Jan-2003') FROM dual;
    TO_DATE('30
    30-JAN-2003HTH
    John

Maybe you are looking for