Hi Adam, I've realised my answer could be a bit too specific (just for one year boundary, Jan to Dec). A more general one would use similar principle where you can get the values of both year(s) and month(s) of the dates you want to check, so for example...
May/2011 and Jan/2013
you would have something like this... [(Year2 - Year1) * 12 + (Month2 - Month1)]
for the case above you should then end up with 20 months between the two dates.
no direct function but not too much to set up. LR.
There is a month-from-dateTime function(xpath though).
In microflows I tend to just grab the month number in a couple of variables and get the difference between the variables.
e.g. : parseInteger(formatDateTimeUTC([%CurrentDateTime%], 'M')) -> this will return integer (1)
If you have another date, you can establish which date is the first which is second and subtract accordingly. Hope it helps. LR.
There is no microflow expression monthsBetween, so you need to calculate it. I tried this approach:
round(daysBetween($date1,$date2)) div 30)
It's not completely accurate but in my case that wasn't really important.
It is strictly mathematically not possible to calculate months between because months have no fixed length. However it is well understood by humans if you say 3,5 months.
Here is my JavaAction that calculates the complete months between two dates (Parameters startDate end endDate).
import java.util.Calendar; import java.util.Date;
// BEGIN USER CODE Calendar end = Calendar.getInstance(); end.setTime(endDate); Calendar start = Calendar.getInstance(); start.setTime(startDate); return (long) ((end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12 + (end.get(Calendar.MONDAY)- start.get(Calendar.MONDAY)) + (end.get(Calendar.DAY_OF_MONTH) > start.get(Calendar.DAY_OF_MONTH) ? 1: 0)); // END USER CODE
Use at your own risk.