Hi Adam,
You can easily execute this within a microflow using the following functions on an input dateTime object called "$inputDate":
addDays( addMonths( trimToMonths($inputDate), 1), -1)
Essentially, you trim your input date to the beginning of that month. Then you add a month to the modified DateTime object. Finally, you subtract one day from the result to get the last day of the previous month.
That should solve your issue immediately. Maybe adding a little logic to check the input date DAY would solve it entirely.
Happy modelling!
Adam,
I don't think there is a standard function to do this but with a little java this is easy. The code below takes a datetime as input, and returns the datetime as the last day of the month taken from the input.
Hope this helps.
import java.util.Calendar;
import java.util.Date;
import com.mendix.systemwideinterfaces.core.UserAction;
/**
*
*/
public class GetLastDay extends UserAction<java.util.Date>
{
private java.util.Date inputDate;
public GetLastDay(java.util.Date inputDate)
{
super();
this.inputDate = inputDate;
}
@Override
public java.util.Date executeAction() throws Exception
{
// BEGIN USER CODE
Calendar cal = Calendar.getInstance();
cal.setTime(inputDate);
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Date resultdate = cal.getTime();
return resultdate;
// END USER CODE
}
/**
* Returns a string representation of this action
*/
@Override
public String toString()
{
return "GetLastDay";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}
Better use addSeconds in stead of addDays -1. In this case addDays returns a 0:00 time and puts you at the beginning of the last day of the months and can result in unexpected result when retrieveing data using a date filter AddSecond returns 23:59 time and really puts you at the end of the last day of the month
Adam You can use the XPATH system variable [%EndOfCurrentMonth%] in a microflow. More information can be found here: XPath Keywords in Reference Guide 4.0
Mike