You already have the interesting parts to change code:

# my $date = $arr_ref->$datecol; # $date =~ s/ //;

I suggest that you take the database out of the problem and start out with a simple subroutine that converts the date to the format you want:

sub fix_oracle_date { my( $date ) = @_; # $date =~ s/ //; return $date }

... and then test your subroutine using (for example) Test::More, which makes this very easy:

use Test::More; is fix_oracle_date('08/02/2018'), '8/2/2018', "Correct date for 8/2/20 +18"; is fix_oracle_date('08/03/2018'), '8/3/2018', "Correct date for 8/3/20 +18"; is fix_oracle_date('08/04/2018'), '8/4/2018', "Correct date for 8/4/20 +18"; is fix_oracle_date('08/13/2018'), '8/13/2018', "Correct date for 8/13/ +2018"; done_testing;

Now you have a good testbed and you can work on implementing fix_oracle_date until it returns the correct data for your input.

Maybe you want to start with the implementation I gave you in my previous reply?

See also How to ask better questions using Test::More and sample data, which outlines this process.


In reply to Re^5: Date format by Corion
in thread Date format by jsuresh

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, details, 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, summary, 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.