web stats
Mirth Community - View Single Post - Mirth Tools: User defined functions
View Single Post
  #8  
Old 04-18-2012, 06:35 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default Converting HL7 DTG to English Date

I'm swamped so can't add much but here's something:

Code:
//presumes YYYYYMMDDHHSS  -although I don't get the time with this one

function DateConvert(strString) {

var months = new Array ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

var year = strString.substring(0,4);
var mm = strString.substring(5,6);
var day = strString.substring(7,8);

return day + ', ' + months[mm] + ', ' + year;


}

This one does the time as well

Code:
function DTGConvert(strString) {


if (strString.length < 9) {     //user requirement

strString = strString + '0000'

}

var months = new Array ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');


var year = strString.substring(0,4);
var mm = parseInt(strString.substring(4,6),10);
var day = strString.substring(6,8);
var hh = strString.substring(8,10);
var min = strString.substring(10,12);

return day + ', ' + months[(mm-1)] + ', ' + year + ' ' + hh + ':' + min;


}
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote