Search code examples
datekshaix

date conversion DD-MMM-YY to YYYYMMDD


How to convert DD-MMM-YY to YYYYMMDD

I am in AIX, using korn shell.

neither date --date nor date -d works in aix.


Solution

  • I did it in perl, the hard way

    sub formatDate_YYYYMMDD 
    {
    my $date=shift;
    my ($day,$mon,$yr) = split /\-/,$date;
    my @months=qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC );
    $i=0;
    foreach $_ (@months)
        {
            $i++; 
            if (/$mon/i){$mon=$i;}
        }
    $year=2000+$yr;
    $mon=sprintf "%02d",$mon;
    print "Invalid month format $date present in $file_name" if $mon ==0;
    return("$year$mon$day");
    }