Issue with converting string to date object

Hi all,
I have a problem with sorting a list of dates in a table column. My dates are in the format 'yyyy-Mmm-dd'(Eg: 2009-Dec-23). Can someone help me how to sort the dates in this format. here is the code which i tried.
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-Mmm-dd");
          Date d1= new Date();
          Date d2= new Date();
          try {
               d1 = dateFormat.parse("2006-Jun-09");
             d2 = dateFormat.parse("2006-Apr-10");
          } catch (ParseException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          System.out.println("converted date 1"+ d1);
         System.out.println("converted date 1"+ d2);
Exception : Unparseable date: "2006-Jun-09"
     }Please someone help me how to pass this date in the right format.

I believe twisai may have lost the documentation so he/she can figure this out rather than guess that "Mmm" means 3-letter month, first letter capitalized. Let me remind him of the link:
[http://java.sun.com/javase/6/docs/api/index.html]

Similar Messages

  • How to convert a string to date object?

    I have a string user input for date.
    I want to convert it to Date object to insert it in database.
    How to do it?

    Check the java.text.SimpleDateFormat class. You can use it for parsing dates. API contains good description how to build the format pattern.
    HTH
    Mike

  • Convert String to Date and Format the Date Expression in SSRS

    Hi,
    I have a parameter used to select a month and year  string that looks like:    jun-2013
    I can convert it to a date, but what I want to do is,  when a user selects a particular month-year  (let's say "jun-2013")
    I  populate one text box with the date the user selected , and (the challenge Im having is)  I want to populate a text box next to the first text box with the month-year  2 months ahead.    So if the user selects 
    jun-2013   textbox A will show  jun-2013 
    and textbox B will show  aug-2013..
    I have tried:
    =Format(Format(CDate(Parameters!month.Value  ),  
    "MM-YYYY"  )+ 2  )   -- But this gives an error
    This returns the month in number format   like "8"    for august...
    =Format(Format(CDate(Parameters!month.Value  ), 
    "MM"  )+ 2  )
    What is the proper syntax to give me the result    in this format =  "aug-2013"  ???
    Thanks in advance.
    MC
    M Collier

    You can convert a string that represents a date to a date object using the util.scand JavaScript method, and then format a date object to a string representation using the util.printd method. For more information, see:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1254.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.1251.html
    In your case, the code would be something like:
    var sDate = "2013-01-10";
    // Convert string to date
    var oDate = util.scand("yyyy-mm-dd", sDate);
    // Convert date to new string
    var sDate2 = util.printd("mm/dd/yyyy", oDate);
    // Set a field value
    getField("date2").value = sDate2;
    The exact code you'd use depends on where you place the script and where you're getting the original date string, but this should get you started.

  • Issue with Oracle LONG RAW data type

    Hi All,
    I am facing some issues with Oracle LONG RAW DATA Type.
    We are using Oracle 9IR2 Database.
    I got a table having LONG RAW column and I need to transfer the same into another table having LONG RAW column.
    When I tried using INSERT INTO SELECT * command (or) CREATE TABLE as select * , it is throwing ORA-00997: illegal use of LONG datatype.
    I have gone through some docs and found we should not use LONG RAW using these operations.
    So I did some basic PLSQL block given below and I was able to insert most of the records. But records where the LONG RAW file is like 7O kb, the inserting is faliling.
    I tried to convert LONG RAW to BLOB and again for the record where the LONG RAW is big in size I am getting (ORA-06502: PL/SQL: numeric or value error) error.
    Appreciate if anyone can help me out here.
    DECLARE
    Y LONG RAW;
    BEGIN
    FOR REC IN (SELECT * FROM TRU_INT.TERRITORY WHERE TERRITORYSEQ=488480 ORDER BY TERRITORYSEQ ) LOOP
    INSERT INTO TRU_CMP.TERRITORY
    BUSINESSUNITSEQ, COMPELEMENTLIFETIMEID, COMPONENTIMAGE, DESCRIPTION, ENDPERIOD, GENERATION, NAME, STARTPERIOD, TERRITORYSEQ
    VALUES
    REC.BUSINESSUNITSEQ, REC.COMPELEMENTLIFETIMEID, REC.COMPONENTIMAGE, REC.DESCRIPTION, REC.ENDPERIOD, REC.GENERATION, REC.NAME,
    REC.STARTPERIOD, REC.TERRITORYSEQ
    END LOOP;
    END;
    /

    Maddy wrote:
    Hi All,
    I am facing some issues with Oracle LONG RAW DATA Type.
    We are using Oracle 9IR2 Database.
    I got a table having LONG RAW column and I need to transfer the same into another table having LONG RAW column.
    When I tried using INSERT INTO SELECT * command (or) CREATE TABLE as select * , it is throwing ORA-00997: illegal use of LONG datatype.
    I have gone through some docs and found we should not use LONG RAW using these operations.
    So I did some basic PLSQL block given below and I was able to insert most of the records. But records where the LONG RAW file is like 7O kb, the inserting is faliling.
    I tried to convert LONG RAW to BLOB and again for the record where the LONG RAW is big in size I am getting (ORA-06502: PL/SQL: numeric or value error) error.
    Appreciate if anyone can help me out here.
    DECLARE
    Y LONG RAW;
    BEGIN
    FOR REC IN (SELECT * FROM TRU_INT.TERRITORY WHERE TERRITORYSEQ=488480 ORDER BY TERRITORYSEQ ) LOOP
    INSERT INTO TRU_CMP.TERRITORY
    BUSINESSUNITSEQ, COMPELEMENTLIFETIMEID, COMPONENTIMAGE, DESCRIPTION, ENDPERIOD, GENERATION, NAME, STARTPERIOD, TERRITORYSEQ
    VALUES
    REC.BUSINESSUNITSEQ, REC.COMPELEMENTLIFETIMEID, REC.COMPONENTIMAGE, REC.DESCRIPTION, REC.ENDPERIOD, REC.GENERATION, REC.NAME,
    REC.STARTPERIOD, REC.TERRITORYSEQ
    END LOOP;
    END;
    /below might work
    12:06:23 SQL> help copy
    COPY
    Copies data from a query to a table in the same or another
    database. COPY supports CHAR, DATE, LONG, NUMBER and VARCHAR2.
    COPY {FROM database | TO database | FROM database TO database}
                {APPEND|CREATE|INSERT|REPLACE} destination_table
                [(column, column, column, ...)] USING query
    where database has the following syntax:
         username[/password]@connect_identifier

  • Problem in  Converting String to Date

    Hi All,
    I am having one String
    String date = "2006-01-17 15:19:57.0"
    I want to parse this String into Date object.
    I will really appriciate if somebody helps me out.
    Thanks.

    You're specifying a 'T' and a timezone in your format, but they're not present in the string you're parsing.
    I'm assuming from the way you're printing out the date, that your thinking is along these lines: "sdfInput will parse the input string, no matter what format it's in, and will produce a Date object. That Date object wil have the format specified in sdfInput."
    This is wrong on a couple of fronts:
    1) DateFormat doesn't magically figure out what format it's supposed to use for the String it's parse()ing. The String has to match the DF's format.
    2) Dates don't have formats. Only Strings do. A Date object is just a long. There's no relationship whatsoever between the Date that you get from parse() and the format that was used to produce it. When you print out a Date as you're doing, its toString method is called, which in turn uses a default format for your Locale.
    If you want to turn a date string in one format into a date string in another format, use two different DateFormat objects with two different formats. Date date = df1.parse(inputString);
    String outputString = df2.format(date);

  • I want convert string to date format in Oracle

    Dear All
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'

    >
    Hi Parwez,
    I want convert string to date format in Oracle,Format is given below
    'Friday, 02 March 2012 2:44 PM' to '02/03/2012 2:44 PM'SELECT TO_DATE('Friday, 02 March 2012 2:44 P.M.', 'DAY, DD MONTH YYYY HH:MI A.M.') from dual;
    As well as what the other poster suggested, look here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924
    HTH,
    Paul...

  • Date string to Date object

    Hi
    How would i go about parsing some date strings in DD/MM/YYYY
    format into a date objects. I am sure its an easy problem but i
    cant find a simple way to do it as most of the API's want it a
    differnt format like MM/DD/YYYY
    Thanks for any help

    Hi,
    in the actionscript 3.0 cookbook there is a class DateFormat
    described, which allows to parse strings to date objects.
    You can download the code of the dateformat.as from here .
    http://www.rightactionscript.com/ascb/
    best regards,
    kcell

  • Converting String to Date

    Hi All,
    I am having a String value which is having date in the format 'Mon Apr 14 16:07:52 IST 2008'
    Now I want to convert this String to Date with format 'mm/dd/yyyy' , to display as 04/14/2008
    Also I want to add 5 days to this date and display the new date 04/19/2008
    I don't know How to convert the string which is having date in 'Mon Apr 14 16:07:52 IST 2008' format to format I need.
    Please help me.

    Hi ,
    I wrote a class that tries to parse a String Date and converts it to object. However, I found a very interesting thing while testing this code. I was trying to paarse "2008:03:04 16:21:05" string by using
    DateFormat.getDateFromString(null,"2008:03:04 16:21:05" )
    It should by pass all try loop accept the one with yyyy:MM:dd HH:mm:ss format. But it went inside the try loop which had MM:dd:yyyy HH:mm:ss format and gave me a wrong date object with year 0171, april 03.
    Could any one help me to understand why it is happening? as a work around I put MM:dd:yyyy HH:mm:ss at the end of the program and it is giving me correct object as it did not have to go that far before matching the format.
    Thanks,
    AL-Amin
    Code:
    import java.text.*;
    import java.util.*;
    public class DateFormat
    public Date getDateFromString(String format, String parseDate)
         Date d;
         if(format!=null) {
    try
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    d = sdf.parse(parseDate);
    catch(Exception e)
    System.out.println(e.toString());
    d = null;
    return d;
         else {
              try
                   format = "yyyy-MM-dd HH mm ss";
         SimpleDateFormat sdf = new SimpleDateFormat(format);
         d = sdf.parse(parseDate);
         catch(Exception e)
         System.out.println(e.toString());
         System.out.println("The Date was not of '"+format+" ' format");
         d = null;
         if(d==null) {
              try
                        format = "yyyy-MM-dd HH:mm:ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "yyyy-MM-dd HH_mm_ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "yyyy-MM-dd HH-mm-ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "yyyy-MM-dd-HH-mm-ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "yyyyMMddHHmmss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "MM-dd-yyyy HH:mm:ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
              if(d==null) {
              try
                        format = "dd-MM-yyyy HH:mm:ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "MM:dd:yyyy HH:mm:ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              try
                        format = "dd:MM:yyyy HH:mm:ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
    if(d==null) {
              try
                        format = "yyyy:MM:dd HH:mm:ss";
              SimpleDateFormat sdf = new SimpleDateFormat(format);
              d = sdf.parse(parseDate);
              catch(Exception e)
              System.out.println(e.toString());
              System.out.println("The Date was not of '"+format+" ' format");
              d = null;
         if(d==null) {
              System.err.println("None of the Date format worked. Please modify the calling method and provide a specific format");
         return d;
    }

  • Issue with Enterprise Library's Data Access Application

    I do not know if I have the correct forum for this post. I hve put it in what I believe is the most likely best forum, but please move this if there is a more germane forum for it.
    I have inherited a solution (C#) which uses the reference Microsoft.Practices.EnterpriseLibrary.Data. The reference was included with the codebase I inherited, there are no missing references.
    When the library is called with:
    Microsoft.Practices.EnterpriseLibrary.Data.ExecuteDataSet("configConfigurationKeysSelect", parameterValues);
    It complains with the runtime error:
    [InvalidOperationException: The stored procedure 'configConfigurationKeysSelect' doesn't exist.] (I have put the full trace below)
    This is true, there IS no stored procedure  'configConfigurationKeysSelect'  but there is a table named  'configConfigurationKeys.'  
    I assumed this stored procedure is built on the fly to select from that table? Must I do something regarding  Enterprise Library's Data Access Application so that this works on the system I am running it on? (I am simply accessing the references
    included with the sourced for this, nothing else). I am looking for some guidance here, and thanks in advance.
    Stack trace on error as:
    [InvalidOperationException: The stored procedure 'configConfigurationKeysSelect' doesn't exist.]    System.Data.SqlClient.SqlCommand.DeriveParameters() +5344249
       System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand command) +115
       Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.DeriveParameters(DbCommand discoveryCommand) +72
       Microsoft.Practices.EnterpriseLibrary.Data.Database.DiscoverParameters(DbCommand command) +251
       Microsoft.Practices.EnterpriseLibrary.Data.ParameterCache.SetParameters(DbCommand command, Database database) +225
       Microsoft.Practices.EnterpriseLibrary.Data.Database.AssignParameters(DbCommand command, Object[] parameterValues) +53
       Microsoft.Practices.EnterpriseLibrary.Data.Database.GetStoredProcCommand(String storedProcedureName, Object[] parameterValues) +161
       Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteDataSet(String storedProcedureName, Object[] parameterValues) +70
    Enterprise Library's Data Access Application 

    This is true, there IS no stored procedure  'configConfigurationKeysSelect'  but there is a table named  'configConfigurationKeys.'  
    I assumed this stored procedure is built on the fly to select from that table? Must I do something regarding  Enterprise Library's Data Access Application so that this works on the system I am running it on? (I am simply accessing the references
    included with the sourced for this, nothing else). I am looking for some guidance here, and thanks in advance.
    Why do you assume that a stored procedure is create on the fly?  Looking at the documentation for this component, I don't see a mention of such.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • Parsing from string to date object

    How can I convert a time in String format to a Date object?
    ie. 14:30:05(String) to 14:30:05

    How about this?
    String sDate = "14:30:05";
    StringTokenizer tokenizer = new StringTokenizer(sDate, ":");
    Calendar calendar = new Calendar();
    int hour = Integer.parseInt(tokenizer.nextToken());
    int minute = Integer.parseInt(tokenizer.nextToken());
    int second = Integer.parseInt(tokenizer.nextToken());
    calendar.set(Calendar.HOUR_OF_DAY, int hour);
    calendar.set(Calendar.MINUTE, int minute);
    calendar.set(Calendar.SECOND, int second);
    Date dDate = calendar.getTime();I didn't try it, but it should be pretty close (unless you want to use deprecated methods, then it can be shorter...)

  • Converting string to date in mm/dd/yyyy format

    Hi,
    I used simpledateformat to convert date to "MM/dd/yyyy" format.
    Now when i want to insert into db, i want the value as date object instead of string [returned by format method of SimpleDateFormat]
    what should i do?
    Date dt = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    System.out.println("Formatted date is coming as "+sdf.format(dt));
    Date dt1 = sdf.parse(sdf.format(dt);
    System.out.println("parsed date is coming as " +dt1);
    output :
    1 SOP returns 11/07/2007 [current date]
    2 SOP returns Wed Nov 07 00:00:00 GMT+05:30 2007

    If you are using PreparedStatements setDate method, you need a java.sql.Date object, not a Java.util.Date object. You can create an sql.Date object from a util.Date object as follows:
    java.sql.Date sqlDate = new java.sql.Date(dt.getTime());And, if you are not using PreparedStatement and its setDate method, then change now.
    Doing
    Date dt1 = sdf.parse(sdf.format(dt));is meaningless. You format the date to string, then parse the string back to a date? Why? Why not just use the original Date object? And you won't get a sql.Date object that way, either, as the DateFormat classes return a util.Date object.
    Edit: And for more info:
    A Date does not have a format. It is simply a number. The "format" only comes into play when printing the String representation of the Date, and that is not handled by the Date object itself (except when calling toString either explicitly or implicitly).

  • How to convert string into date datatype

    hi! there
    i've a date in string format like MM/dd/yyyy
    eg:String sDate = "01/30/2002";
    and i want to convert this string format into java date format
    same as 01/30/2002 only
    when i write like this
    SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy");
              String sDate = "1/11/2002";
              java.util.Date oDate = formatter.parse(sDate);
    i'm getting the output
    Fri Jan 11 00:00:00 GMT+05:30 2002
    i just want the out put like 01/30/2002
    plz,help me

    Hi,
    Just use back the SimpleDateFormat object you defined.
    String myDateInStr = formatter.format(oDate);
    this will format a java.util.Date object to a string representation according to the format you specified in the instantiation of SimpleDateFormat object.

  • Hoe to pass String to Date object

    Guys,
    I want to convert the String 01/03/07 09:15:26 to a Date object.
    Pls guide me.

    Hi,
    Try the following:
                    DateFormat df = new SimpleDateFormat ("dd/MM/yy hh:mm:ss");
              try
                   Date date = df.parse("01/03/07 09:15:26");
                   System.out.println(date);
              catch (ParseException e)
                   e.printStackTrace();
              }Regards,
    Kumar

  • Convertion string to Calender object

    The input string format is "hh-mm-ss". How can I convert to Calender object.
    Can anybody suggest ?
    Thanks
    Pravat

    Use a java.text.SimpleDateFormat to convert the string to a java.util.Date object and then set the calendar object from that.

  • Convert RichInputDate to Date object

    Hi,
    I'm using af:inputDate in my form.
    in my backing bean i'm trying to get the value as Date object.
    public RichInputDate getFromDate() {
    return fromDate;
    public void convert(){
    Date fromDt = (Date)this.getFromDate().getValue();
    but I get this error:
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
    any idea?
    is there a simple way to get the value as Date object.
    Thanks!

    Converting RichInputDate to specific format
    https://kr.forums.oracle.com/forums/thread.jspa?threadID=2242338

Maybe you are looking for

  • Account determination error in FI-MM

    Hi Gurus I trying to raise PO requisition in ME21N. Here I am facing couple of issues 1) If I select the K in account assignment category I can't assign the raw material GL account in account assignment tab  as it falls under balance sheet item. 2) I

  • Problem with UNIQUE field parameter in Release 2

    (using Enterprise Manager) I started with 9i Release 1 and began creating tables, setting a field called ID to not null, primary key, and unique. No problem in Release 1. I updated to Release 2 (removed Release 1 and fresh-installed Release 2), and a

  • Screen Fading on Macbook Pro just over a year old

    My screen is fading around the edges and a line across the middle of the screen as if the coating is wearing off. I have done nothing but take car of my mac. NO Chemicals no rubbing just a light dusting every now and again with micro fibre cloth I ac

  • After effects cc not loading after signing up

    Hi there, my free trail expired so i signed and paid up for After Effects CC, however when I lauch the app it tells me the trial has expired and I need to enter a serial code. Have checked my emails but been sent nothing. Please help as I desperately

  • Apple care registration

    Hi! I have bought a Macbook in New York on september 22. I have Apple Care for it. The instruction says, that I have to register it via internet to activate. Go to apple.com, etc...Select the link Register your apple care agreement. Entering my Apple