The CreatorCon Call for Content is officially open! Get started here.

Unable to format date in Transform Map

jxa7987
Tera Expert

I'm importing data from JDBC and getting date error:

"Unable to format 20,210,526 using format string yyyy-MM-dd for field due_by (Date Time field) "

In field map the date format I set:

 

 

find_real_file.png

Please help how to resolve this. Thanks.

1 ACCEPTED SOLUTION

That's different. In which case, I would eliminate the commas and format accordingly. Here is proof that you can run in Scripts - Background:

var oString = '20,210,526';
var nString = oString.replace(/,/g, "");
gs.info(nString);
var yyyy = nString.slice(0,4);
var mm = nString.slice(4,6);
var dd = nString.slice(6,8);

gs.info(yyyy);
gs.info(mm);
gs.info(dd);

var gd = new GlideDate();
gd.setDate(yyyy + '-' + mm + '-' + dd);
gs.info(gd);

View solution in original post

5 REPLIES 5

ccajohnson
Kilo Sage

Looking at the numeric string it may be just the number of seconds to add. Do you have a start date field? If not, you can always use the current date/time and add that number of seconds:

answer = (function transformEntry(source) {
    var dt = new GlideDateTime();
    dt.addSeconds(20210526);
    return dt;
})(source)

Thanks for your response @ccajohnson but the 20,210,526 is not the number of seconds but should be date: 2021 /05/26

That's different. In which case, I would eliminate the commas and format accordingly. Here is proof that you can run in Scripts - Background:

var oString = '20,210,526';
var nString = oString.replace(/,/g, "");
gs.info(nString);
var yyyy = nString.slice(0,4);
var mm = nString.slice(4,6);
var dd = nString.slice(6,8);

gs.info(yyyy);
gs.info(mm);
gs.info(dd);

var gd = new GlideDate();
gd.setDate(yyyy + '-' + mm + '-' + dd);
gs.info(gd);

Frank Tate
Giga Guru

Adding on to the great answer by @ccajohnson , it looks to me like the value in your data is being seen as the string "20210526". So you should either set your Date Format to "yyyymmdd" (as opposed to "yyyy-mm-dd") or use the script provided by @ccajohnson to change it to that format.

Frank