web stats
Convert Date to specific format - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2014, 01:34 AM
discofris discofris is offline
OBX.1 Kenobi
 
Join Date: Jan 2014
Location: Belgium
Posts: 46
discofris is on a distinguished road
Question Convert Date to specific format

Hello.

This is my input date:
Code:
20141231
yyyMMdd
And I would like to have this output:
Code:
2000-10-25T10:24:00
yyyy-MM-ddTHH:mm:ss
I've tried the code from narupley http://www.mirthcorp.com/community/f...1&postcount=27 but I don't know how to add the extra
Code:
THH:mm:ss
Unfortunatley the time isn't given in the HL7 message.

Any help highly appreciated!
Reply With Quote
  #2  
Old 01-09-2014, 02:38 AM
rodrosa rodrosa is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 79
rodrosa is on a distinguished road
Default

you can use DateUtil to do that:

Code:
DateUtil.convertDate('yyyyMMdd', 'yyyy-MM-ddTHH:mm:ss', "DATE VAR");
But if time dont come in HL7 it should appears 00:00:00
Reply With Quote
  #3  
Old 01-09-2014, 02:53 AM
discofris discofris is offline
OBX.1 Kenobi
 
Join Date: Jan 2014
Location: Belgium
Posts: 46
discofris is on a distinguished road
Default

Quote:
Originally Posted by rodrosa View Post
you can use DateUtil to do that:

Code:
DateUtil.convertDate('yyyyMMdd', 'yyyy-MM-ddTHH:mm:ss', "DATE VAR");
But if time dont come in HL7 it should appears 00:00:00
Thanks for the reply.
How do I use this in my transformer JavaScript?
Code:
tmp.ns::['ddtBirthdate'] = DateUtil.convertDate(msg['PID']['PID.7']['PID.7.1'].toString(), 'yyyyMMdd', 'yyyy-MM-ddTHH:mm:ss', "DATE VAR");
Reply With Quote
  #4  
Old 01-09-2014, 04:40 AM
rodrosa rodrosa is offline
OBX.2 Kenobi
 
Join Date: Jul 2013
Posts: 79
rodrosa is on a distinguished road
Default

the first parameter is the inbound mask, in your case: yyyyMMdd

the seccond is the outbound mask, in other words your expected date format: yyyy-MM-ddTHH:mm:ss

the last parameter is the variable that has the value in according of your inbound mask, for you: msg['PID']['PID.7']['PID.7.1'].toString()

So:
Code:
tmp.ns::['ddtBirthdate'] = DateUtil.convertDate('yyyyMMdd', 'yyyy-MM-ddTHH:mm:ss', msg['PID']['PID.7']['PID.7.1'].toString());
Reply With Quote
  #5  
Old 01-09-2014, 04:52 AM
discofris discofris is offline
OBX.1 Kenobi
 
Join Date: Jan 2014
Location: Belgium
Posts: 46
discofris is on a distinguished road
Thumbs up

Got it now ...

But to have the T between date and time I had to do this:

Code:
tmp.ns::['ddtBirthdate'] = DateUtil.convertDate("yyyyMMdd", "yyyy-MM-dd'T'HH:mm:ss", msg['PID']['PID.7']['PID.7.1'].toString());
THX!
Reply With Quote
  #6  
Old 12-18-2015, 05:31 PM
PHCMirth PHCMirth is offline
What's HL7?
 
Join Date: Dec 2015
Posts: 4
PHCMirth is on a distinguished road
Post Converting date 20151210031240-0600

Can someone please help me in converting the date in the following format ;

20151210031240-0600

I would like to convert the above to datetime format in sql server.

to datetime format in sql server.

This is what i tried so far

Code:
var rawdate =msg['OBR']['OBR.7']['OBR.7.1'].toString();;
var formatter = java.text.SimpleDateFormat("yyyyMMddhhmm");
var date = formatter.parse(rawdate);
I`m getting the following error:

Conversion failed when converting date and/or time from character string.
Reply With Quote
  #7  
Old 01-04-2016, 02:24 AM
discofris discofris is offline
OBX.1 Kenobi
 
Join Date: Jan 2014
Location: Belgium
Posts: 46
discofris is on a distinguished road
Default

This topic contains enough info to answer the question yourself
__________________
Mirth Connect Server 3.4.1.8057
Java version: 1.8.0_101

on Debian 8.5 and various Winboxes
Reply With Quote
Reply

Tags
convert, date, time

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 02:35 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation