in reply to Re^4: Date format
in thread Date format
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.
|
|---|