• Index
  •  » Talend Open Studio for Data Integration » Installation
  •  » date formate convertion at TALEND side by perl

#1 2007-01-05 12:29:58

alankar_kumar
Member
Registered: 2007-01-03
Posts: 33

date formate convertion at TALEND side by perl

hi
as your routines  section   have many predefine subroutine   and  "getDate" is one of them
sub getDate {
    my ($format) = @_;
    $format = 'DD/MM/CCYY' if not defined $format;
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    my %fields = (
        CC => int(($year + 1900) / 100),
        YY => $year % 100,
        MM => $mon + 1,
        DD => $mday,
        hh => $hour,
        mm => $min,
        ss => $sec
    );
    %fields = map {$_ => sprintf('%02u', $fields{$_})} keys %fields;
    foreach my $field (keys %fields) {
    $format =~ s/$field/$fields{$field}/g;
    }
    return $format;
}

my input date formate is "03-FEB-59 12.00.00.000000 AM"
can you suggest  what  change we made so that  we can convert it into "02/03/1959"

Offline

#2 2007-01-05 14:31:48

plegall
Member
Registered: 2006-09-19
Posts: 1586
Website

Re: date formate convertion at TALEND side by perl

Here is a routine doing what you want (I think):

Code:

sub AlankarToUsDate {
    my ($us_date) = @_;
    
    my %month_number_of = (
        JAN => 1,
        FEB => 2,
        MAR => 3,
        APR => 4,
        MAY => 5,
        JUN => 6,
        JUL => 7,
        AUG => 8,
        SEP => 9,
        OCT => 10,
        NOV => 11,
        DEC => 12,
    );
    
    # '03-FEB-59 12.00.00.000000 AM'
    
    $us_date =~ m/(\d\d)-([a-z]{3})-(\d\d)/i;
    
    my $day = $1;
    my $month_name = $2;
    my $two_digits_year = $3;
    
    my $four_digits_year = undef;
    if ($two_digits_year > 50) {
        $four_digits_year = 1900 + $two_digits_year;
    }
    else {
        $four_digits_year = 2000 + $two_digits_year;
    }
    
    return sprintf(
        '%02u/%02u/%4u',
        $month_number_of{$month_name},
        $day,
        $four_digits_year
    );
}

Offline

#3 2007-01-19 16:13:12

alankar_kumar
Member
Registered: 2007-01-03
Posts: 33

Re: date formate convertion at TALEND side by perl

can you tell me how to write code for adding   date
e.g
ADD_TO_DATE(SYSDATE,  'YY', -115)
ADD_TO_DATE(SYSDATE,  'DD',  95)
ADD_TO_DATE(SYSDATE,  'MM',  05)

Offline

#4 2007-01-19 16:42:32

cantoine
Talend team
Registered: 2006-09-19
Posts: 763
Website

Re: date formate convertion at TALEND side by perl

Hi,

Before install the Date::Calc perl module.

After, you can add to your own routine the following function :

Code:

#
# ADD_TO_DATE(Today(),  'YY', -115)
#
sub getDateYY {

    use Date::Calc qw/Today Add_Delta_YMD/; 
    my ($yearNumber, $monthNumber, $dayNumber) = @_;
    
    return sprintf(
        "%u%02u%02u",
        Add_Delta_YMD(Today(), $yearNumber, $monthNumber, $dayNumber)
        );
}

Code:

#
# ADD_TO_DATE(SYSDATE,  'DD',  95)
#
sub getDateDD {

    use Date::Calc qw/Today Add_Delta_YMD/; 
    my ($yearNumber, $monthNumber, $dayNumber) = @_;
    
    return sprintf(
        "%u%02u%02u",
        Add_Delta_YMD(Today(), $yearNumber, $monthNumber, $dayNumber)
        );
}

Code:

#
# ADD_TO_DATE(SYSDATE,  'MM',  05)
#
sub getDateMM {

    use Date::Calc qw/Today Add_Delta_YMD/; 
    my ($yearNumber, $monthNumber, $dayNumber) = @_;
    
    return sprintf(
        "%u%02u%02u",
        Add_Delta_YMD(Today(), $yearNumber, $monthNumber, $dayNumber)
        );
}

Regards

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Installation
  •  » date formate convertion at TALEND side by perl

Board footer

Powered by FluxBB