Is it possible to add two dates in CTL?
Specifically I need to add a date and a time.
trunc(today()) + trunc_date($0.Start);
where $0.Start is 23:59:59
Thanks
Des
Is it possible to add two dates in CTL?
Specifically I need to add a date and a time.
trunc(today()) + trunc_date($0.Start);
where $0.Start is 23:59:59
Thanks
Des
Hello,
you can use dateadd function, eg.:
string time;
long hours;
long min;
long sec;
date newDate;
// Transforms input record into output record.
function transform() {
time = date2str($0.field1,"hh:mm:ss");
hours = str2num(substring(time,0,2));
min = str2num(substring(time,3,2));
sec = str2num(substring(time,6,2));
newDate = dateadd(trunc(today()),hours, hour);
newDate = dateadd(newDate,min,minute);
$0.field1 := dateadd(newDate, sec, second) ;
}
Thanks for the reply. Seems like a lot of work. Was kinda hoping there was a simple way.
What about date2long for both, add them and then use some function to get a date from a long number? Is there such a function?
Thanks
Des
Yes, you’re right:
//#TL
long newDate;
long zeroDate = date2long(str2date("0001-01-01","yyyy-MM-dd"));
long now = date2long(trunc(today()));
// Transforms input record into output record.
function transform() {
newDate = now + date2long(trunc_date($field1)) - zeroDate;
$0.field1 := long2date(newDate);
}
Sweet. That’s better. Thanks for the help
Des
Hi deshartman,
You can find an overview of our CTL functions at the following two sites:
http://www.cloveretl.com/_upload/clover … k/apf.html
(which is a part of our on-line Users Manual)
and
http://wiki.cloveretl.org/doku.php?id=t … _functions
(part of our wiki pages).
CloverETL also includes a new CTLFunctionsTutorial project demonstrating the use of individual CTL functions.
Best regards,
Tomas Waller