web stats
Add days - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2013, 05:30 AM
Souren Souren is offline
Mirth Newb
 
Join Date: Jul 2013
Location: UK
Posts: 12
Souren is on a distinguished road
Send a message via Skype™ to Souren
Default Add days

I am trying to figure out how to add n days to a given date
An example would be a discharge date, if non is specified then take current date and add n days to it
Have used DateUtil to get the date, the AddDays method is not apparently available.

Anybody out there have a solution?
Reply With Quote
  #2  
Old 09-04-2013, 07:02 AM
sandersmr sandersmr is offline
OBX.2 Kenobi
 
Join Date: Feb 2013
Posts: 71
sandersmr is on a distinguished road
Default

One way is to use the Calendar object.

e.g.
Code:
var currentDTTM = new java.util.Calendar.getInstance(); //get current datetime
currentDTTM.add(java.util.Calendar.DATE, 2); //add 2 days
//if you want to parse this out, use SimpleDateFormat
var strCurrentDTTM = new java.text.SimpleDateFormat("yyyyMMdd HH:mm:ss").format(currentDTTM.getTime());
Reply With Quote
  #3  
Old 09-04-2013, 07:35 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,117
narupley is on a distinguished road
Default

You can also use Joda-Time (included by default):

Code:
if (!msg['PV1']['PV1.45']['PV1.45.1'].toString())
	msg['PV1']['PV1.45']['PV1.45.1'] = org.joda.time.format.DateTimeFormat.forPattern('yyyyMMddHHmmss').print(new org.joda.time.DateTime().plusDays(2));
__________________
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.

Last edited by narupley; 09-04-2013 at 07:38 AM.
Reply With Quote
  #4  
Old 09-04-2013, 10:48 AM
glen4medica glen4medica is offline
Mirth Newb
 
Join Date: Apr 2011
Location: Eugene, Oregon
Posts: 19
glen4medica is on a distinguished road
Default

in Javascript you can do:

var theDay = new Date ();
theDay.setDate (theDay.getDate () + NUMBER_OF_DAYS_IN_PAST_OR_FUTURE);
Reply With Quote
Reply

Tags
adddays, dateutil

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 06:44 AM.


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