Monday, January 17, 2011

Dynamically changing datetime format in BIRT

It's really easy to change the format of a datetime data value. One may change the onPrepare function of the data item, and then

switch (params["d1"].value) {
 case "YE": this.getStyle().dateTimeFormat = "YYYY"; break;
 case "MO": this.getStyle().dateTimeFormat = "YYYY MMMM"; break;
 //case "WK": row["dtWeek"]; break;
 case "DY": this.getStyle().dateTimeFormat = "YYYY MMMM DD"; break;
 case "HO": this.getStyle().dateTimeFormat = "YYYY MMMM DD hh:00:00"; break;
 case "HH": this.getStyle().dateTimeFormat = "YYYY MMMM DD hh:mm:00"; break;
 //default: row["dtHalfHour"]; break;
}
So based on the value of the parameter named d1, the report will format the datetime value as year, year and month etc etc.