Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm presently dealing with an application where an external vendor sends me xml data that gets then parsed by my Perl script and saved in our database for future retrieval and etc. One of the xml fields is date stamp for the data.

Unfortunately, defying my pleas for consistent date formats, the vendor keeps sending me data with date stamp strings of varying 'composition'. On one occassion, I'd get '2002-08-23 11:39:24.0', or 'Fri Aug 23 12:14:04 2002', or ... This complicates my task of formating these date strings into something that Oracle would accept (when inserting data into the database via an INSERT sql statement). In my parser configuration, I set expected date format string to 'DY MON DD HH24:MI:SS YYYY'. So, my parser would affectively work only on data files that have a date stamp string of matching format. Otherwise, Oracle would complain since the TO_DATE would always fail. For example, TO_DATE('2002-08-23 11:39:24', 'DY MON DD HH24:MI:SS YYYY') is bound to fail; whereas this should work TO_DATE('2002-08-23 11:39:24', 'YYYY-MM-DD HH24:MI:SS').

So, my question is whether anyone of you knows of any Perl method or module (I couldn't find) that would allow me to build a Oracle date format string from (such as 'YYYY-MM-DD HH24:MI:SS') a date string (such as '2002-08-23 11:39:24')?

Update: I can't predict all valid date format variations that the vendor may use. That was the only reason I asked if there's any module that could do something like this, so that I won't have to ;-).

As I look at it now, I could use Class::Date to create a date object from vendor date string and then reformat it in one format that Oracle would understand. This is actually a reverse look at my initial 'question'.
use Class::Date; # . . . # make sure that whatever date format the vendor chooses to use # the one that will come out of this parser conforms to the format # specified in the configuration. my $date_obj = new Class::Date($data_xml_tag->att('date')); $vendor_data{date} = $date_obj->strftime($CONFIG::ORACLE_DATE_FORMAT +); # . . . later in the code . . . my date_f = "TO_DATE('" . $vednor_data{date} . "','" . $CONFIG:: +ORACLE_DATE_FORMAT . ")"; # I then use date_f in my insert SQL statements ...


_____________________
# Under Construction

In reply to Computing Oracle date format from a date string by vladb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (8)
    As of 2019-06-25 13:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Is there a future for codeless software?



      Results (106 votes). Check out past polls.

      Notices?