Date calculation x days - System date

0 votes
asked Jun 3, 2020 by jeremy-c-6009 (300 points)

Reviewed and attempted to follow the above article with adjustment of months rather than days and getting an invalid return date.    

Tried   90 days and 3 months and both returned same results  Originally I thought bad value may be due to addDays possibly limiting to a single month



var DateUtils = org.apache.commons.lang.time.DateUtils;
var fromdate90 = qie.formatDate('YYYY-MM-DD', DateUtils.addMonths(qie.deduceDate(qie.getSystemDate()),-3));
qie.debug('fromdateCalced ' + fromdate90);


[path=1-2-3] - fromdateCalced 2020-03-63

2 Answers

0 votes
Best answer

The format date uses the standard java annotation for the format.  The java docs can be found here:

The format you are using is:
YYYY = week year (meaning the year for the first day in the week)
MM = month in year
DD = day in year

You probably want:
yyyy = year (meaning the year for the given day)
MM = month in year
dd = day in month

Change the format from 'YYYY-MM-DD' to 'yyyy-MM-dd' to get the desired output.

var DateUtils = org.apache.commons.lang.time.DateUtils;
var fromdate90 = qie.formatDate('yyyy-MM-dd', DateUtils.addMonths(qie.deduceDate(qie.getSystemDate()),-3));
qie.debug('fromdateCalced ' + fromdate90);

answered Jun 3, 2020 by ben-s-7515 (12,640 points)
selected Jun 3, 2020 by jeremy-c-6009
commented Jun 3, 2020 by jeremy-c-6009 (300 points)
Perfect thanks for the clarification on the date part syntax, so actually was my formatDate function that failed not the addMonths.    
Made this correction and it is successfully returning the date now.
0 votes
If you want to use the evaluate template option you can specify the days back or ahead.



The system date node tag is replaced with the current system date/time in the specified format (see Format Indicator above) The system date/time can be adjusted by adding a modifier after SYSTEM_DATE in the format of [+/-][number][y/M/d/H/m/s/S]. For example, to adjust it ahead 2 hours, you could use the following syntax: {SYSTEM_DATE+2H[yyyy-MM-dd]}
answered Jan 24, 2023 by michael-h-5027 (14,350 points)