Converting a java string to a date.

I am working on extending an EO and I have a situation where I must convert a string to a date before passing it to a method. The string is in the format "DD-MON-YYYY". I am using the following code and get an error "incompatible types: found: java.util.Date, required: oracle.jbo.domain.Date". Here is the code I am using:
try {
SimpleDateFormat df=new SimpleDateFormat("DD-MON-YYYY");
oracle.jbo.domain.Date expdate=df.parse(expendituredate);
setExpenditureItemDate(expdate);
catch (Exception err) {
Any ideas why the code I am using is not working? Is there another way to do this?
Mike

The difference is that
D Day in year
d      Day in month
Hence when you used 22-Feb-2007 with "DD-MMM-yyyy", it took 22 as the 22nd day of the year and overrided the month value giving you 22nd January :)
Cheers
--Saroj                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Converting a text string to a date in Discoverer

    I've got a problem with a discoverer report which is that an item is pointing to a field in the Oracle table which is named as a segment4. This appears to be a generic field which stores any type of data, as it is based on the result of a flex-field in the application, so you could have dates, text, numbers etc. The problem is that the dates are stored in the table back to front i.e. 2004/10/19 00:00:00 and I need to be able to convert the date values so they are in the format DD-MON-YYYY as is this is the format that we use for all our reporting. When I try to apply any kind of date function it doesn't seem to work because it's a text field. I've used SUBSTR to get the first 10 characters and then used it again to split into day, month, year and then concatinated the values into one field in the correct order. This works to a certain degree but still doesn't recognise the value as being a date because because it doesn't sort them in order i.e. 20-06-2007 would appear before 30-06-2005. I'm not sure whether Discoverer could fix the problem or whether it may something the DBA may have to apply to the table. Does anyone have any suggestions to how I can get around this problem?
    Thanks.
    Joanne Hulme, Bolton Council.

    Hi,
    You can use TO_DATE(segment4, 'YYYY/MM/DD HH24:MI:SS') in a calculation to convert the segment to a oracle date type.
    You can then format the date in anyway you need.
    Rod West

  • Converting 3 Strings to 1 Date?

    Hi first of i am very new at this sql. But my problem is that i am haveing 3 combo boxes in java. 1 with dd 1 with mm and 1 with yyyy. How do i convert these 3 strings into 1 date format? Writing the Gui in java.
    It is to a booking system so i need it for a fromdate and then the same in a todate function. Hope u understand my problem.
    Best regards
    Jakob

    take care of 1 digit days/months. (ex 31-2 != 3-12). So if you have digits, you could use to_date(d||'.'||m||'.'||y,'DD.MM.YYYY)Message was edited by:
    Laurent Schneider
    31-2 very clever example ! Sorry about that...

  • Cannot convert from java.util.Date to java.sql.Date

    In the below code am trying to get the current date and 60 days prior date:
    Date  todayDate;
              Date  Sixtydaysprior;
              String DATE_FORMAT = "MM/dd/yy";
              DateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
             Calendar cal = Calendar.getInstance();
              todayDate = sdf.parse(sdf.format(cal.getTime()));
              cal.add(Calendar.DATE, -60);
             Sixtydaysprior = sdf.parse(sdf.format(cal.getTime()));I have imported following files:
    <%@page
         import="java.util.Calendar,
                   java.text.SimpleDateFormat,
                   java.text.ParseException,
                            java.util.*"
    %>Shows up following error msg:
    Type mismatch: cannot convert from java.util.Date to java.sql.Date
    Thanks.
    Edited by: MiltonDetroja on May 22, 2009 11:03 AM

    Shows up following error msg:
    Type mismatch: cannot convert from java.util.Date to java.sql.Date
    I don't think this exception is thrown from the portion of code you have shown. As clearly specified in exception message, you cannot cast an instance of java.util.Date to java.sql.Date. you will need to do something like this
    java.util.Date today = new java.util.Date();
    long t = today.getTime();
    java.sql.Date dt = new java.sql.Date(t);

  • Convert String to sql date

    hi all,
    i have a date in string format Tue, 06 Feb 2007 12:38:17 GMT
    How do i convert it to sql datetime.
    Date date = new Date("Tue, 06 Feb 2007 12:38:17 GMT");// creating date
              java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
                        "yyyy-MM-dd HH:mm:ss");// format definition
              java.sql.Time pubDate = java.sql.Time.valueOf(sdf.format(date));
              System.out.println(pubDate);This code gives me java.lang.NumberFormatException.
    Thanks in advance.......
    VikraM

    is "EEE d MMM yyyy HH:mm:ss Z" your default data format
    if not your first constructor will not parse date properly so your date object contains invalid date, when you try to format it it throws exception.
    check it
    sudhir nimavat

  • How to convert a string into orcle date format

    i need some information about converting string into date format.i have string like '20-SEP-05' .so we have to convert into date formate like yy-mm-dd' (2005-09-20).how can we do it.

    Here's some code to help. I can't remember what method uses what format though
      public static java.sql.Date sqlDateValueOf( String dateString ) {
        String stringDate = null;
        if ( dateString == null || dateString.length() < 10 ) return null;
        String strDay = "";
        String strMonth = "";
        String strYear = "";
        if ( dateString.substring(4,5).equals( "-" ) ) {
          strDay = dateString.substring(8, 10);
          if ( strDay.length() < 2 ) strDay = "0" + strDay;
          strMonth = dateString.substring(5, 7);
          strMonth = dateString.valueOf(Integer.parseInt(strMonth) - 1);
          if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
          strYear = dateString.substring(0, 4);
          stringDate = strDay + "-" + strMonth + "-" + strYear;
        else if ( dateString.substring(2,3).equals( "-" ) ) {
          strDay = dateString.substring(0, 2);
          if ( strDay.length() < 2 ) strDay = "0" + strDay;
          strMonth = dateString.substring(3, 5);
          strMonth = String.valueOf(Integer.parseInt(strMonth) - 1);
          if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
          strYear = dateString.substring(6, 10);
          stringDate = strDay + "-" + strMonth + "-" + strYear;
        Calendar cal = Calendar.getInstance();
        cal.set( Calendar.YEAR, Integer.parseInt( strYear ) );
        cal.set( Calendar.MONTH, Integer.parseInt( strMonth ) );
        cal.set( Calendar.DAY_OF_MONTH, Integer.parseInt( strDay ) );
        java.sql.Date outDate = new java.sql.Date( cal.getTimeInMillis() );
        return outDate;
      public static String toDateString( java.util.Date date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Date date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Date date, String format) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat( format );
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Timestamp date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      }

  • Slow to convert Oracle 11g XMLType into Java String or Document

    After retrieving a result set from an Oracle 11g database, it takes roughly 75 seconds to convert the XMLType (this is a structured XML Storage, registered with an xsd) into either a java String or Document. I'm using Java 1.6, have the xdb.jar and xmlparserv2.jar
    This xsd is <100 lines and the xml document is also <100 lines.
    Sample code:
    oracle.xdb.XMLType xml = oracle.xdb.XMLType.createXML((oracle.sql.OPAQUE)rset.getObject("XMLDATA"));
    the other way, but still took just as long:
    XMLType xml = (XMLType)rset.getObject("XMLDATA");
    xml.getStringVal();
    or
    org.w3c.dom.Document doc = xml.getDocument();
    either way of the above ways takes just as long.

    If I put this value into the database table, I can
    see only the date. Time part is missing. Is this the
    problem with java.sql.Date or Oracle datatype Date?This is not a problem, this is the defined behaviour of the Date type. RTFAPI and have a look at Timestamp, while you're at it.

  • Error in converting character string to smalldatetime data type

    I've installed SQL Server 2000 on my new laptop and Crystal Report XI, out of sudden, the Crystal Report to certain view can't run and I got the following error:
    Details: 22007 [Microsoft][ODBC SQL Server Driver][SQL SERVER]Syntax Error cnverting character string to smalldatetime data type.
    Any suggestions?
    Hannah

    Here is the view the err is complaining about:
    SELECT     TOP 100 PERCENT Cur.Closed_Month, Cur.Closed_Year, Cur.Incidents_Closed, Prev.Incidents_Closed AS PrevIncidents_Closed,
                          YrAgo.Incidents_Closed AS YearIncidents_Closed
    FROM         (SELECT     Closed_Month, Closed_Year, Incidents_Closed
                           FROM          dbo.Incidents_Closed) Cur INNER JOIN
                              (SELECT     Month(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevMonth,
                                                       year(CONVERT(datetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 32) AS PrevYear,
                                                       Incidents_Closed
                                FROM          dbo.Incidents_Closed) Prev ON Cur.Closed_Month = Prev.PrevMonth AND Cur.Closed_Year = Prev.PrevYear INNER JOIN
                              (SELECT     Month(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevMonth,
                                                       year(CONVERT(smalldatetime, CAST(closed_month AS varchar) + '/01/' + CAST(closed_year AS varchar), 101) + 366) AS PrevYear,
                                                       Incidents_Closed
                                FROM          dbo.Incidents_Closed) YrAgo ON Cur.Closed_Month = YrAgo.PrevMonth AND Cur.Closed_Year = YrAgo.PrevYear
    What confused me is that it works fine with my previous laptop. I wonder if there is any patch in Crystal Report or SQL server that used to support certain functions but not support them anymore....
    Thanks
    Hannah

  • Converting part of the string to a date and subtract with sysdate.

    HINT! In order solve this you must know how the pnr is assembled. Study this:
    650323-5510, we only need the first six characters. They inform us about when the person (car owner) was born. In this case it is 23 Mars 1965. You have to use several oracle built-in-functions to solve this. Hint! Begin by converting part of the string to a date and subtract with sysdate.
    select to_char(to_date(cast(pnr,'YYMMDDMM'))) from car_owner;
    please what am i doing wrong. i need the result to be something like this
    Hans, Rosenboll, 59,6 years.

    Hi.
    The main problem here is you have only last two digits of year. That could be the problem in a couple of years from now, when somebody born after 2k would get in to your database. For now if we ignore this problem the right solution would be :
    <code>
    SELECT months_between(trunc(SYSDATE),
    to_date('19' || substr('650323-5510',
    1,
    6),
    'YYYYMMDD')) / 12 years_old
    FROM dual
    </code>
    Suppose you are expecting the age of the car owner as a result above code will give you that. One again notice the '19' I appended.
    Best regards.

  • Setting compile date & time to a Java String variable

    I was wondering does the NetBeans IDE have a capability to grab the current compile date & time and set it to a Java String, updating it at each compile. I know you can set is in a template, but isn't that fixed once forever when the file is created.
    Just wondering.

    If you're using Ant you can have it maintain a file with the last build date in it, and that can be a .java file if you so desire.
    Applications should be completely recompiled before shipping or deployment so it doesn't really make sense to have a compile date per Java source file.

  • Converting Oracle XML Query Result in Java String by using XSU

    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

    Hmmm.. Pretty basic just look at the example:
    OracleXMLQuery qry = new OracleXMLQuery(conn,"Select max(ps.datum) from preise ps where match='"+args[0]+"'");
    String xmlString = qry.getXMLString();
    Hi,
    I have a problem by converting Oracle XML Query Result in Java
    String by using XSU. I use XSU for Java.
    For example:
    String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
    preise ps where match='"+args[0]+"'");
    String datum1=datum;
    I become the following error:
    Prototyp.java:47: Incompatible type for declaration. Can't
    convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
    Can somebody tell me a method() for converting to solve my
    problem??????
    Thanks

  • ORA-01830: date format picture ends before converting entire input string at OCI call OCIStmtFetch

    Hi all,
    We are trying to create a BIP Data Model based on an Answer, but after selecting report, it hangs when I try to Apply to create a query based on Oracle BI. When I try to open the query in aswers, going to results tab I'm getting this error (OBIEE 11.1.1.6.2):
    ORA-01830: date format picture ends before converting entire input string at OCI call OCIStmtFetch
    I suppose that BIP data model is not able to create it because of this error. But this answer is working fine inside dashboards, etc. It only does not work when editing it. Query is doing something like this: "USING "- Collection Attributes"."Due Date" >= TIMESTAMPADD(SQL_TSI_DAY, -30, CAST ('01/04/2009' AS DATE))"
    Any ideas?

    Solved watching date format in generated SQL and changing default date format in presentation variables default values inside criteria according to SQL format.

  • Date Format Picture ends before converting entire input string..

    Hi all
    i am creating a report in 10g.. in which i want to convert Emp_lump_sum (number)  to character .I have created a formula column in which i have written a function in the formula column and assign that formula column to the text field in which i want the result.
    when the report run i get the following error....
    ORA-01830: date format picture ends before converting entire input string..
    i have tried with a attribute EMP_NO (Varchar2(30)), it shows the result but when i add EMP_LUMP_SUM (NUMBER) , it show the above error. on the database side i get the same error.
    Database : 11g
    OS :     Windows server 2003
    reports   : 10g
    any help will be thankful..
    Function i wrote behind the formula coloumn is..
    function CF_1Formula return CHAR is
    xy varchar2(100);
    begin
      select to_char(to_date(emp_lump_sum,'j'),'jsp') into xy from fms_111_form4_tr;
        return xy;
        --xy := f_19;
    end;

    Hello:
    Try to use a database function and call it from reports.
    Regards,

  • How to convert number to string in java

    hi how can i convert number to string in java
    something like
    public void Discription(Number ownerName){
    String.valueOf(ownerName);Edited by: adf009 on 2013/04/08 7:14 PM

    Yet another way of doing it is: ownerName.toString().
    If you are working in and IDE such as Netbeans or Eclipse, type a period after the object name. Wait a second or so. Eclipse/Netbeans Intellisense will show you a list of functions that object provides that you can choose from. toString() is one of them.

  • Help converting between Java Dates and SQL Dates

    Hey all,
    I'm working on a JSP to allow a user to enter information about news articles into a mySQL database. I'm using text fields for most of the data, and most of it is transferred correctly when the user hits "Submit." However, I am having a problem with the date field of the mySQL database. Basically I'm trying to retrieve the current date from the JSP page, and then insert this into the date field of the appropriate table when the user hits submit. The problem is that I can't typecast a java.util.Date or even a java.util.Calendar to a java.sql.Date object. I've tried lots of approaches, including creating a new instance of java.util.Calendar, getting all its fields and concatenating them onto the date variable, but this doesn't work.
    Anyone know how I could easily convert between java.util.Date or java.util.Calendar and java.sql.Date?
    Thanks!

    Thanks for the help!
    I can correctly display the current date on the page in java.sql.Date format now, but it's still not being inserted into the database correctly. The specific code is as follows:
    java.util.Date dt = new java.util.Date();
    java.sql.Date sqlDate = new java.sql.Date(dt.getTime());
    (As you wrote)
    Then (after connecting to the database etc.):
    PreparedStatement pstmt = con.prepareStatement("INSERT INTO NEWS(NEWSDATE,DAYOFWEEK,AUTHOR,HEADLINE,CLIP,PUBLICATION,LINK,NEWSLOCATION,DATECREATED,DATEMODIFIED,CATEGORY,KEYWORDS,PHOTOURL,PHOTOGRAPHER,AUDIOURL) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    pstmt.clearParameters();
    pstmt.setString(1,date);
    pstmt.setString(2,dayofweek);
    pstmt.setString(3,author);
    pstmt.setString(4,headline);
    pstmt.setString(5,clip);
    pstmt.setString(6,publication);
    pstmt.setString(7,link);
    pstmt.setString(8,newslocation);
    pstmt.setDate(9,sqlDate);
    pstmt.setString(10,datemodified);
    pstmt.setString(11,category);
    pstmt.setString(12,keywords);
    pstmt.setString(13,photoURL);
    pstmt.setString(14,photographer);
    pstmt.setString(15,audioURL);
    int i = pstmt.executeUpdate();
    pstmt.close();
    All the other fields are retrieved with request.getParameter from text fields. Any idea why the DATECREATED field is being updated to all 0's but the others work fine?
    Thanks again.

Maybe you are looking for

  • How do I change the way that my company name appears when googled?

    How do I change the way that my company name appears when it is googled?  Currently it only shows up as part of my company name followed by the website listed below and then the start of a description.  I would like to make it so my entire company na

  • Intel GMA 950 & Dual Monitor

    Does anyone have a working config of an i810 driver for Dual Monitors mode?

  • Connecting Oracle Warehouse Builder to an Informix data source

    I am having trouble connecting Oracle Warehouse Builder to my Informix database. I am getting error ORQ-28545. Here is what I did: Under Project Explorer I went to Non-Oracle under Datases. Then right click on Informix and selected New. In the Create

  • Boot Camp won't start in Windows 8

    Hi All, I got the new MacBook Pro with Retina Display this week and I installed Windows 8 Release Preview with Boot Camp. The reason I used Windows 8 is because the Retina Display is not supported in Windows 7 yet. The dual boot and drivers are all f

  • Tab traversal in TextArea

    I have the following code so that when the TAB key is pressed, focus traverses to the next field. All is well EXCEPT...before it traverses to the next field, it inserts a TAB character into the control, indenting any existing content. I don't want th