web stats
Yesterday's Date Filename - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2012, 12:48 PM
rmcginness rmcginness is offline
What's HL7?
 
Join Date: Nov 2011
Posts: 5
rmcginness is on a distinguished road
Cool Yesterday's Date Filename

Greetings,

I have spent more hours than I care to admit trying to figure out how to create my own custom Destination Mapping variable for a "Date -1"

scenario. I have only found javascript code examples but there is no step by step instructions on where to place the code and how to execute.

Details: FTP source to an FTP destination no tranformation scrictly passing data.

I am using Mirth Connect Version 2.1.1.5490

I would greatly appreciate any help. Thanks in advance!
Reply With Quote
  #2  
Old 03-14-2012, 06:10 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

If you're dealing with a java.util.Date, I believe you can do something like Date.setTime(Date.getTime()-(1000*60*60*24)). Even better though is to use a java.util.Calendar object. Then you can just call .add(Calendar.DATE,-1).

From there, you can either invoke a SimpleDatePattern yourself, or use DateUtil to convert the date to a string specified by an output pattern.
Reply With Quote
  #3  
Old 03-15-2012, 01:50 AM
StefanScholte StefanScholte is offline
 
Join Date: May 2009
Location: Netherlands, Harderwijk
Posts: 321
StefanScholte is on a distinguished road
Default

Here's what I needed a while ago.

Code:
var kalender = java.util.Calendar.getInstance();
kalender.add(java.util.Calendar.DATE, -1);

//format: yyyyMMdd
var date = kalender.get(kalender.YEAR).toString()+ZeroPadLeft((kalender.get(kalender.MONTH)+1).toString(), 2)+ZeroPadLeft(kalender.get(kalender.DATE).toString(), 2) + "";
ZeroPadLeft is used to fill the leading zero's (selfmade function)
the reason I use + "" at the end is to ensure it is a javascript string rather than a java string object.
Reply With Quote
  #4  
Old 06-13-2012, 03:36 PM
albac albac is offline
What's HL7?
 
Join Date: Oct 2010
Posts: 1
albac is on a distinguished road
Default

Thanks! I just needed this for a filename, in the source transformer.
You can use getTime() and DateUtil.formatDate instead of your ZeroPadLeft function as in the following code:

Code:
var kalender = java.util.Calendar.getInstance();
kalender.add(java.util.Calendar.DATE, -1);

//format: yyyyMMdd
var yesterday = DateUtil.formatDate("yyyyMMdd",kalender.getTime());
Reply With Quote
  #5  
Old 08-16-2012, 12:30 PM
rmcginness rmcginness is offline
What's HL7?
 
Join Date: Nov 2011
Posts: 5
rmcginness is on a distinguished road
Default Yesterday's Date Filename

What I am trying to do is use the "Destination Mappings" variables under the destinations tab to create a filename with yesterday's date for the output.

I have tried adding "-1" to this example below but doesn't work.

Example: myfile_${date.get('yyyy-M-d H.m.s')}
Reply With Quote
  #6  
Old 08-16-2012, 12:35 PM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,124
narupley is on a distinguished road
Default

You could probably do this in the template by calling date.getDate(), etc. But an easier way is to add a transformer step that puts your pre-formatted date string into the connector map. Then, you'll be able to drag it over from the Destination Mappings frame.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
Reply

Tags
date, destination, filename, mappings, yesterday

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 09:51 PM.


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