How to format a Date to use as input in a tMAP

One Star

How to format a Date to use as input in a tMAP

On the Help menu I found this piece of code, that allow me to format a datetime.
use POSIX qw(strftime);
$now_datetime = strftime "%Y-%m-%d %H:%M:%S", gmtime;
How can I put this to be an value of one output column in the tMap? May I use a variable to do this, or I can write an expression?
I already put this in the selected column (see image in attach) but when I run it gives me this error:
use POSIX qw(strftime);
strftime "%Y-%m-%d %H:%M:%S", gmtime;
or
use POSIX qw(strftime);
$now_datetime = strftime "%Y-%m-%d %H:%M:%S", gmtime;
(Expecting that the last line executed is what will be inserted in the output column )
String found where operator expected at
D:\JAVA\TOS-2.0.0M2\TOS-Win32-r2461-V2.0.0M2\workspace\.Perl\TALEND_2.job_Teste_exp1.pl line 3067, near
"strftime "%Y-%m-%d %H:%M:%S""
(Do you need to predeclare strftime?)

To resume, all I want is format a date an put that in a output collumn in tMAP component.
Thanks in advance Smiley Wink
Tags (1)
One Star

Re: How to format a Date to use as input in a tMAP

Here is the image ... Smiley Tongue
Employee

Re: How to format a Date to use as input in a tMAP

Create a routine file with the following content:
use Exporter;
use vars qw(@EXPORT @ISA);
@ISA = qw(Exporter);
@EXPORT = qw(
getNow
);
sub getNow {
use POSIX qw(strftime);
return strftime "%Y-%m-%d %H:%M:%S", gmtime;
}
1;

Use this function in your tMap as described in the screenshot.
Starting job topic397 at 17:03 21/03/2007.
1|2007-03-21 16:03:28
2|2007-03-21 16:03:28
3|2007-03-21 16:03:28
4|2007-03-21 16:03:28
5|2007-03-21 16:03:28
Job topic397 ended at 17:03 21/03/2007.

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads