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

Highlighted
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
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.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog