Home
Analytics
How to add a day to a date parameter
rmendonsa
How would I write sql for Actualdate between params["StartDate"] and params["StartDate"] + 1 in Maximo BIRT?
Thanks.
Find more posts tagged with
Comments
RobR
Looks like a 2 part question:
To get the End Date, you can either use the appropriate functions in whatever flavor of SQL you are using (Oracle, MS SQL, or ???), or if you want to do it in BIRT, you could do something like this:
reportContext.setParameterValue("endDate", BirtDateTime.addDay(params["StartDate"] ,1));
Before you can use the date in SQL (I am assuming the parms have a Data Type of DateTime), you need to convert them to a sting:
var sdf = new SimpleDateFormat("M/d/yyyy", reportContext.getLocale());
var string_startDate = sdf.format(params["StartDate"].value);
var string_endDate = sdf.format(params["EndDate"].value);
Then handle the string value in the SQL Statement (Oracle Version):
sqlText ="some sql" +
"AND TRUNC(Actualdate) BETWEEN TO_DATE(?, 'mm/dd/yyyy') AND TO_DATE(?, 'mm/dd/yyyy')" +
maximoDataSet.setQuery(sqlText);
maximoDataSet.setQueryParameterValue(1, string_startDate );
maximoDataSet.setQueryParameterValue(2, string_endDate );
You might need imports to do this stuff:
importPackage(Packages.com.ibm.tivoli.maximo.report.script);
importPackage( Packages.java.text );
wwilliams
Try the following;<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>+ " and matrectrans.actualdate >= " + MXReportSqlFormat.getStartDayTimestampFunction(params["sDate"]) ;
+ " and matrectrans.actualdate < " + MXReportSqlFormat.getStartDayTimestampFunction(params["sDate"]) + " + 1 "
</pre>
<br />
-Wes
mwilliams
You could probably also just bring in your date parameter and write your where statement in the beforeOpen of your dataset script:
this.queryText = this.queryText + " where actualDate between '" + params["StartDate"] + "' and '" + BirtDateTime.addDay(params["StartDate"],1) + "'"