SpagoBI Groovy LOV for Last Day of Last Month

SpagoBI Lookup Value (LOV) in Groovy to get the last day of last month

1
2
3
4
5
6
7
8
9
10
11
12
Calendar cal = Calendar.getInstance()
cal.add(Calendar.MONTH, -1)
cal.set(Calendar.DATE, 1)
Date firstDateOfPreviousMonth = cal.getTime()
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE))
Date prevDate = cal.getTime()
 
//You pick whether you like sprintf or GString better
//String returnStr = "${(cal.get(Calendar.MONTH)+1).toString().padLeft(2,'0')}/${(cal.get(Calendar.DATE)).toString().padLeft(2,'0')}/${cal.get(Calendar.YEAR)}"
//return returnStr.toString()
String returnStr = sprintf("%02d/%02d/%4d", cal.get(Calendar.MONTH)+1, cal.get(Calendar.DATE), cal.get(Calendar.YEAR))
return returnStr

Getting the first day of the last month for a SpagoBI LOV default date value is slightly easier

1
2
3
4
5
6
7
8
9
10
Calendar cal = Calendar.getInstance()
cal.add(Calendar.MONTH, -1)
cal.set(Calendar.DATE, 1)
Date firstDateOfPreviousMonth = cal.getTime()
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE))
Date prevDate = cal.getTime()
 
 
String returnStr = sprintf("%02d/01/%4d", cal.get(Calendar.MONTH)+1, cal.get(Calendar.YEAR))
return returnStr

1-lov

2-lov-detail

3-ad-detail

4-report-param

5-report-param-prompt

Comments |0|

Legend *) Required fields are marked
**) You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
In category: Uncategorized
Tagged with: ,