Mirth Connect SQL Server Error : Conversion failed when converting date and/or time from character string -


i trying insert sql server datetime field. trying simple scenario of 1 table having datetime column named start_date only.

query trying

insert test (start_date) values (${start_date}) 

start_date channelmap variable of type java.util.date , created using :

var start_date = dateutil.getdate('yyyymmddhhmmss', msg['date'].tostring()); 

here start_date of java.util.date, why mirth treats string when tries insert database ??

you can handle conversion in sql. hope helps

var start_date = msg['pid']['pid.7']['pid.7.1'].tostring(); // 19831123 - yyyymmdd format try {   sql="insert test (start_date) values (convert(datetime,'" + start_date + "',5))";   logger.info(sql);   rst = dbconn.executeupdate(sql);   } catch(err) {   logger.info('err: ' + err); } 

out in db below.

select * test start_date | ---------- 1983-11-23 00:00:00.000 

2nd approach

if still want use util try below

var start_date = msg['pid']['pid.7']['pid.7.1'].tostring(); // 19831123 - yyyymmdd format /*  input yyyymmdd ,  output yyyymmddhhmmss format */ var datestring = dateutil.convertdate('yyyymmdd', 'yyyymmddhhmmss', start_date);  try {   sql="insert test (start_date) values ('" + start_date + "')";   logger.info(sql);   rst = dbconn.executeupdate(sql);   } catch(err) {   logger.info('err: ' + err); } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -