Improving my date parsing

Hi, I have two methods that I use together to parse dates from raw text files:
I format the date with this:
public static String formatDate(String date){
          String[] parts = null;
          String yr = "";
          String mn = "";
          String dy = "";
          String pad = "0";
          if(date.contains("/")){
               parts = date.split("/");
               if(parts.length==3){
                    if(parts[0].length()==4){
                         yr = parts[0];
                         mn = parts[1];
                         dy = parts[2];
                    }else if(parts[2].length()==4){
                         yr = parts[2];
                         mn = parts[0];
                         dy = parts[1];
          }else if(date.contains("-")){
               parts = date.split("-");
               if(parts.length==3){
                    if(parts[0].length()==4){
                         yr = parts[0];
                         mn = parts[1];
                         dy = parts[2];
                    }else if(parts[2].length()==4){
                         yr = parts[2];
                         mn = parts[0];
                         dy = parts[1];
          if(dy.length()==1){
               dy = pad+dy;
          if(mn.length()==1){
               mn = pad+mn;
          return yr+mn+dy;
     }Then I parse the formatted date with this:
public static synchronized Date asOfDate(String str) {
          //System.out.println("here it is"+str);
          Date dd = null;
          Date ddd = null;
          if(str.contains("/")){
               SimpleDateFormat sdf2 = new SimpleDateFormat("MMddyyyy");
          str = str.replace("/", "");
          String yr = str.substring(0, 4);
          String mn = str.substring(4, 6);
          String d = str.substring(6, 8);
          System.out.println(yr);
          System.out.println(mn);
          System.out.println(d);
          String dddd = mn+ d + yr;
          //System.out.println(dddd);
          try {
               dd = sdf2.parse(dddd);
          } catch (ParseException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          }else{
               SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
               try {
                    dd= sdf2.parse(str);
               } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
          return dd;
     }My question is even if I try to prevent the exceptions by checking the String length before formatting, I still keep getting Exceptions. Im just trying to only run these two methods of the String looks good. What am I doing wrong?
I try to do this:
if((string.length()==8))
string date = TradeHelper.formatDate(temp.substring(84, 92);
//then
TradeHelper.asOfDate(date);Im trying for this:
If the date ="", don't try anything.
but this doesn't seem to work.
java.text.ParseException: Unparseable date: ""
     at java.text.DateFormat.parse(DateFormat.java:335)
     at helper.TradeHelper.asOfDate(TradeHelper.java:213)
     at dazl.DAZLClass.parseFile(DAZLClass.java:127)
     at dazl.DAZLClass.main(DAZLClass.java:48)I know this is stupid, but I'm a little buried right now and could use the extra eyes.

How about sometime like the following to parse dates with / in them. You don't have to remove them first.
public static Date asOfDate(String dateStr) {
  String format;
  switch(dateStr.indexOf('/')) {
    case 4: format = "yyyy/MM/dd"; break;
    case 2: format = "MM/dd/yyyy"; break;
    default: throw new IllegalArgumentException("Unknown format for "+dateStr);
  SimpleDateFormat sdf = new SimpleDateFormat(format);
  return sdf.parse(dateStr);
}

Similar Messages

  • Date parse error while importing users from OIM to OIA (SRM 5.0.3)

    Hi All,
    Env Details:
    OIA (SRM 5.0.3), Weblogic and Oracle 10g DB
    We have integrated OIM to OIA with extended attributes mapping by modifying iam-context.xml file to load users. Its done successfully. But when we map "Date" related attribute, its giving "Date Parsing error" and its not loading the users.
    We have tried loading users using flatFile mechanism, its also giving same result.
    Please suggest me. Thanks in Advance !!!
    Regards,
    Ravi G.

    Hi,
    Its a problem with OOB's OIMIAMSolution.class file, which is called while importing users from OIM. It used DateParse () conversion method only for all attributes which OIA attributes' name is ends with "Date". It defined, the conversion of date from (yyyy-MM-dd). So its expecting the input value should be in defined format(yyyy-MM-dd), if not, it gives a parse error.
    We found work around for this as follows,
    We have used other related OIA attribute which name ends other than "Date" string.
    Thanks,
    Ravi G.

  • Customer Data Parser

    Hi everyone,
    I'm trying to execute a CDP process but I get this error:
    02070E ERROR: Missing required field names in the input DDL. Occurred in Customer Data Parser - (CCDParser::CheckInputFieldNames).
    Does anyone knows what the problem could be?
    Thanks!

    This is best accomplished in the data reconstructor. The customer data parser willl break apart the house number, street name and all the addition address information into their own buckets. Then use the data reconstructor to rebuild the address, taking only the parts you need.
    Keep in mind that the additional information is crucial for correct delivery and postal discounts. You may want to think about the long-term uses of this data before you strip that information out.
    Steve Sarsfield

  • Input agent date parsing error

    Hi all,
    I am using input agent which points to documents which are exported from IPM 10g.in IPM 11g when i pass sample file for that documents which contain 18 fields one of which is date field.so when i pass input file through input agent which contain date value then i get date parsing error .
    please experts help me.
    Thanks in advance
    Edited by: 862821 on Oct 12, 2012 12:01 AM
    Edited by: 862821 on Oct 12, 2012 12:04 AM
    Edited by: 862821 on Oct 12, 2012 12:09 AM
    Edited by: 862821 on Oct 12, 2012 1:18 AM

    Hi srinath,
    I am using input agent which points to documents which are exported from IPM 10g.in IPM 11g when i pass sample file for that documents which contain 18 fields one of which is date field.so when i pass input file through input agent which contain date value then i get date parsing error . please suggest me solution.
    Thanks
    Edited by: 862821 on Oct 12, 2012 1:18 AM

  • Date parsing anyone?

    i am trying to parse this date string:
    "09:35:59 Aug 29 2005"
    using this code:
                                  SimpleDateFormat SDF = new SimpleDateFormat("hh:mm:ss MMM dd yyyy");
                                  Date time = SDF.parse(line,new ParsePosition(0));
                                  System.out.println("Date: " + time.toString());However, i keep getting a NULL value back for the Date Object time. What am I
    doing wrong? Anyone?? Bueller? Bueller?
    thanks!

    From the API:
    public Date parse(String text, ParsePosition pos)
    The method attempts to parse text starting at the index given by pos. If parsing succeeds, then the index of pos is updated to the index after the last character used (parsing does not necessarily use all characters up to the end of the string), and the parsed date is returned. The updated pos can be used to indicate the starting point for the next call to this method. If an error occurs, then the index of pos is not changed, the error index of pos is set to the index of the character where the error occurred, and null is returned.
    Maybe your Locale isn't English?
    Try this:
    System.out.println("Locale: " + java.util.Locale.getDefault());
    String line = "09:35:59 Aug 29 2005";
    SimpleDateFormat SDF = new SimpleDateFormat("hh:mm:ss MMM dd yyyy");
    ParsePosition parsePos = new ParsePosition(0);
    Date time = SDF.parse(line, parsePos);
    if (time == null)
       System.out.println("errorIndex is: " + parsePos.getErrorIndex());
    else
       System.out.println("Date: " + time.toString());
    }

  • BI services error "Data parsing failed, premature end of file".

    Hi all,
    we are facing issue while using BI services whenever we are trying to drill data its showing the error as "Data parsing failed contact your system administrator,premature end of file".
    please share with me if anyone has faced the same error anytime.
    thank in advance for your valuable suggestions.
    Thanks,
    karan.

    Hi,
    Please check whether the RFC imported by you contain the exact elements of XML.  I feel the RFC generated does not contain proper XML schema.
    Regards
    Krish

  • 3D data parsing error in Adobe Reader X 10.1.2

    Hello,
    I'm getting the annoying (and once fixed in version 9) 3D data parsing error with reader X 10.1.2 (on Windows 7 64bit), reading files that used to have no issues with previous versions (Italian locale). Anyone is having the same problem - or is able to give some suggestions? I've already tried to repair the installation, with no result. Any comment is greatly appreciated - this issue is causing major problems.
    Best regards,
    SV

    Hello,
    unfortunately it's a reserved document. I'll try to reproduce the issue with a different design and, if possible, I'll post a link to it.
    Thank you!
    Best regards,
    SV

  • 3D PDFs in Adobe Reader - "3D Data Parsing Error"

    Hi,
    I have just updated my adobe reader to 9.4.2 and I am regreting it already.  I use 3D PDFs on a regular basis and the ones I have that worked perfectly fine in 9.4.1 now do not work.  They come up with:
    "A 3D Data Parsing Error has occured"
    Does anyone know why this happens and particularly how to fix it, preferablly without going back to the older version of adobe reader.
    Many thanks.

    hey mark,
    i've got the same problem after updating to 9.402 this message appears and i cannot open the 3d scene.
    I found this (http://forums.adobe.com/message/2537356#2537356) thread and this link in it (http://communities.bentley.com/communities/everything_else_community/f/289/p/47047/106414. aspx#106414).
    hope that these can help you.
    regards frank

  • MRP planning improved delivery date

    Hello you all,
    I have a question regarding the MRP planning of improved delivery dates. Let me schedule the scenario.
    As material is ordered, the expected delivey date is indicated by delivery rules. If for some reason the supplier can deliver earlier, this is mentioned in the PO tab Confrmations confirmation catagory AB.
    As we run the MRP via transaction V_V2, the updated delivery date is not shown in MD04.
    What do i need to do to see the correct data in MD04?
    If this is all a bit fuzzy, please ask for further details. I am not a SD consultant.
    Thanks in advance for your reply.
    Best Regards,
    Peter Lans

    Hi,
    Run the program SDRQCR21 in SA38.
    This will correct the data in MD04.
    Hope this helps.
    Regards

  • Optimize a data parser that converts CLOB into table

    I am importing complex array data from Cold Fusion into ORACLE using a stored procedure. What I've done is convert the data into a CLOB, pass it into ORACLE, then parse it into a temporary table using a pipelined function. Unfortunately the array is large (16k rows) and it's taking a while to run.
    What I'm looking is a better optimization for the data conversion. I've tried XML and the dbms_xmlstore but it was too slow. I am on 10g and don't have access to the log files or even the ability to trace anything. All I can do is look for better ways to do things and then try them.
    Any suggestions or help to improve things would be welcome.
    Warren Koch
    The function converts the array of object into a custom delimited CLOB ( ; betwen values, | between rows) that looks like this:
    prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|prop1;prop2;prop3|
    Here is the code I created.
    CREATE OR REPLACE TYPE THE_IMAGE_TYPE AS OBJECT
    IMAGE_NAME VARCHAR2(100),
    IMAGE_SIZE INTEGER,
    IMAGE_LOC INTEGER
    CREATE OR REPLACE TYPE THE_IMAGE_TABLE AS TABLE OF THE_IMAGE_TYPE
    CREATE GLOBAL TEMPORARY TABLE IMAGE_IMPORT
    image_name VARCHAR2(25 BYTE),
    loc NUMBER(11),
    image_size NUMBER(11)
    ON COMMIT PRESERVE ROWS
    NOCACHE;
    FUNCTION convert_image_data(
         in_image_clob IN CLOB
         RETURN the_image_table PIPELINED
    AS
         image_clob CLOB := in_image_clob;
         image_delim_index PLS_INTEGER;
         image_index PLS_INTEGER := 1;
         row_string VARCHAR2(1000);
         out_rec THE_image_type;
    BEGIN
         out_rec := the_image_type(NULL, NULL, NULL);
         IF SUBSTR(in_image_clob, -1, 1) != '|'
         THEN
              image_clob := image_clob || '|';
         END IF;
         image_delim_index := INSTR(image_clob, '|', image_index);
         WHILE image_delim_index > 0
         LOOP
              row_string := SUBSTR(image_clob, image_index, image_delim_index - image_index);
              row_string := REPLACE(row_string || '::::', ':', ' :');
              out_rec.image_name := SUBSTR(TRIM(REGEXP_SUBSTR(row_string, '[^:]+', 1, 1)), 1, 25);
              out_rec.image_loc := make_number(REGEXP_SUBSTR(row_string, '[^:]+', 1, 2));
              out_rec.image_size := make_number(REGEXP_SUBSTR(row_string, '[^:]+', 1, 3));
              PIPE ROW(out_rec);
              image_index := image_delim_index + 1;
              image_delim_index := INSTR(image_clob, '|', image_index);
         END LOOP;
         RETURN;
    EXCEPTION
         WHEN OTHERS
         THEN
              RAISE;
    END;
    Used in my code like this:
    EXECUTE IMMEDIATE 'TRUNCATE TABLE image_import';
    FOR x IN (SELECT * FROM TABLE(convert_image_data(in_imagelist))
    WHERE image_name IS NOT NULL)
    LOOP
    INSERT INTO image_import (image_name, loc, image_size)
                   VALUES (x.image_name, x.image_loc, x.image_size);
    END LOOP;

    Is there any chance you can just use 1 SQL statement here? I gave it a shot based on the string you posted, not by trying to reverse engineer your code so it's possible i got it entirely wrong :)
    select
        regexp_substr(image_row, '[^;]+', 1, 1) as image_name,
        regexp_substr(image_row, '[^;]+', 1, 2) as image_size,
        regexp_substr(image_row, '[^;]+', 1, 3) as image_loc   
    from
       select
           regexp_substr(the_data, '[^|]+', 1, level) as image_row
       from
          select
             'prop1;prop2;prop3|prop4;prop5;prop6|propa;propb;propc|propd;prope;propf|' as the_data
          from dual
       connect by level <= length (regexp_replace(the_data, '[^|]+'))  + 1
    17  where image_row is not null;
    IMAGE_NAME                     IMAGE_SIZE                     IMAGE_LOC
    prop1                          prop2                          prop3
    prop4                          prop5                          prop6
    propa                          propb                          propc
    propd                          prope                          propf
    4 rows selected.
    Elapsed: 00:00:00.00

  • Applescript date parsing has changed

    i have been using a script i wrote 7 years ago to convert a string in mm/dd/yyyy format to an a/s date object, and as of last week it was working perfectly.
    tonite i just tried it and "11/05/2012" is parsed as 11may rather than 5nov...something changed the a/s parser's fmt...i suspect the xcode update i just did whenever it came out...
    <Edited by Host>

    yes, and apparently the xcode updte CHANGED MY LOCALIZATION SETTINGS without telling me:-P
    i've fixed the problem by avoiding a/s string2date coersion(what i shoulda done in the 1st place)-:
    -- dtp = [yyyy,mm,dd,hh,mm,ss]
    set dt to (current date)
    set day of dt to 1
    set year of dt to ((item 1 of dtp) as integer)
    set month of dt to ((item 2 of dtp) as integer)
    set day of dt to ((item 3 of dtp) as integer)
    set hours of dt to ((item 4 of dtp) as integer)
    set minutes of dt to ((item 5 of dtp) as integer)
    set seconds of dt to ((item 6 of dtp) as integer)

  • Date Parsing

    Hi,
    I have a string in mm/dd/yyyyy format.
    I want to convert this string in yyyy-mm-dd format.
    I am using simpledateformat to convert it into a Date object.
    It gives me "Thu Jan 26 00:00:00 EST 2006" this object.
    When i parse it again using SimpleDateFormat to convert it into yyyy-mm-dd format it gives me
    2006-00-26 it makes the month 00.
    Please let me know whats the problem or any other better solution to achieve the same

    public static String FORMAT = "MM/dd/yyyy";
         public static String YEAR_FORMAT = "yyyy-mm-dd";
         public static java.util.Date parseDate(String date){
              java.util.Date dateParsed = null;
              try{
                   DateFormat date_formatter = new SimpleDateFormat(FORMAT);
                   date_formatter.setLenient(false);
                   dateParsed = date_formatter.parse(date);
                   System.out.println("Inside the sco****************"+dateParsed);
              catch(ParseException e){
                   e.printStackTrace();
              return dateParsed;
         public static String parseDateYear(String date){
              String dateParsed = null;
              try{
                   SimpleDateFormat date_formatter = new SimpleDateFormat(YEAR_FORMAT);
                   dateParsed = date_formatter.format(parseDate(date));
                   System.out.println("Inside the sco****************"+dateParsed);
              catch(Exception e){
                   e.printStackTrace();
              return dateParsed;
    Thats how i m doing it

  • Date parsing problem inside java

    Hi,
    I'm passing a date string in format yyyy-MM-dd and trying to convert into a date value using below code by parsing the string. But, interestingly the output that i'm getting from dateVal is coming as - Tue Apr 17 00:00:00 GMT 2012 instead of 2012-04-17
    Not able to understand why so.
    String s1 = "2012-04-17";
    SimpleDateFormat outFmt = new SimpleDateFormat("yyyy-MM-dd");
    Date dateVal = outFmt.parse(s1);
    Please help.
    Regards,
    prodyut

    927428 wrote:
    String statement="select * from TIMINGTABLE WHERE COUNTRY = 'USA' AND ";
    statement=statement+"RE_DATE >= '"+dateVal+"'" ;
    df.format(dateVal) // will give you "2012-04-17"FYI : Use tags in start and end of your codes to post codes in this forum                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 01.01.0000 date parse and format

    Could somebody explain is wrong here?
    SimpleDateFormat frm = new SimpleDateFormat("yyyyMMddHHmmss");  // formatter
    frm.setTimeZone(TimeZone.getTimeZone("UTC"));   // UTC time zone
    // --- No problem for the next code ---
    String inDate = "19700101000000";  // 01.01.1970 input date
    long stamp;
    try {
        stamp = frm.parse(inDate).getTime();   // input date in long
    } catch (ParseException ex) {
        System.out.println("Interruption");
        stamp = 0;
    String outDate = frm.format(stamp);  // output date
    System.out.println("inDate=>" + inDate + "_longDate=>" + stamp + "_outDate=>" + outDate);
    // --- No idea why next code is working wrongly ---
    inDate = "00000101000000";  // 01.01.0000 input date
    try {
        stamp = frm.parse(inDate).getTime();   // input date in long
    } catch (ParseException ex) {
        System.out.println("Interruption");
        stamp = 0;
    outDate = frm.format(stamp);  // output date
    System.out.println("inDate=>" + inDate + "_longDate=>" + stamp + "_outDate=>" + outDate);I try to parse and format the time stamp 01.01.0000 00:00:00. On the finish I have 01.01.0001 instead of the correct 01.01.0000
    inDate=>19700101000000_longDate=>0_outDate=>19700101000000
    inDate=>00000101000000_longDate=>-62167392000000_outDate=>00010101000000

    You are calling format with a long parameter. The only format that matches that signature that I can see would be Format.format(Object) assuming autoboxing is changing the long to a Long.
    Format.format(Object) eventually calls DateFormat.format(Object, StringBuffer, FieldPosition). I have never used this method so I am not sure what it does.
    Was your intention to actually call this method?
    See the following example:
    System.out.println("Test 1: " + frm.format(new Long(0l), new StringBuffer(), new FieldPosition(0)));  
    System.out.println("Test 2: " + frm.format(new Long(-62167392000000l), new StringBuffer(), new FieldPosition(0)));  
    Test 1: 19700101000000
    Test 2: 00010101000000Edited by: jbish on Apr 26, 2013 12:43 PM
    Edited by: jbish on Apr 26, 2013 1:09 PM

  • (non-lenient) date parse fails on specific day

    Hi,
    I need help figuring out his problem. I tried running code below using 1.5 and I always get an "unparseable date" exception.
    String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    String date = "2008-03-09 02:00:00";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    sdf.setLenient(false);
    Date d = sdf.parse(date);
    System.out.println(d);If the call to setLenient is omitted, the parse succeeds but the prints out "Sun Mar 09 03:00:00 EDT 2008" instead of the expected "Sun Mar 09 02:00:00 EDT 2008".
    Interestingly enough, the parse succeeds for other dates (with lenient set to false). Examples I tried were ""2008-03-09 01:00:00", "2008-03-09 03:00:00", "2008-02-09 02:00:00", ""2008-04-09 02:00:00".
    I need help in figuring this out. Is this a bug in the jdk itself or am I missing something.
    Btw, I'm using 1.5.0_13.
    Thanks.
    -Anthony

    Wow, that was dumb of me to not think of that. I verified it and you're right. DST change was on Mar-09-2008 02:00:00.
    Thanks masijade. One less headache for me.
    - Anthony

Maybe you are looking for

  • Need a program which finds out if a user has not logged for 3 days?

    HI,    I NEED A PROGRAM WHICH FINDS OUT IF ANY USER HAS NOT LOGGED FOR THREE DAYS     AND SEND A MAIL TO THE BASIS TEAM.IT SHOULD BE SHEDULED AS A BACKGROUND PROCESS. I SEARCHED IN GOOGLE BUT NOT ABLE TO FIND IT. PLEASE HELP ME OUT WITH THIS.        

  • How to avoid Conformed Audio in CS5.5 for large files?

    I have been an avid hater of the conformed audio files since they were introduced. It's not like my 8 core computer can't mix audio in realtime. Please Adobe is there ANY way to avoid them? What about for AME? there is no realtime playback in AME so

  • Why can't I find/access my recent downloads and imessage with the new IOS software update?

    I just recently updated my phone to the new IOS 7 software. I had to do this using my computer. It updated ok but now when I try to find apps that I downloaded (from the computer again) I am unable to locate them. I did find one app that was download

  • My emac keeps freezing!!! any help please

    Hello, my emac keeps freezing. I tried to use the first aid and got this message. "Repair attempted on two volumes, 1 HFS volume repaired 1 volume could not be repaired" I can't reistall the Os because my installation disk is scratched. any help plea

  • General OEM Question

    Can anyone give me a general idea I have created one simple job where I count the number of rows in a table but now I would like to send the output to my e-mail. Also if anyone has some sample code that can give me an idea on how to creat other jobs