---
title: "Date Range Parameters in Jasper Reports with SQL Server"
date: 2010-12-30T23:49:37+00:00
author: "poornerd"
canonical: https://www.poornerd.com/2010/12/30/date-range-parameters-in-jasper-reports-with-sql-server/
source: Raw Markdown twin of the HTML article; content is the original source.
---
Ok, to some this might be obvious but I just spent about 4 hours trying to figure out how to use parameters to select a date range in a Jasper Report report based on a JDBC / SQL query to a Microsoft SQL Server.

﻿First you need to define your parameter as a java.sql.Timestamp like this:

<pre class="brush: plain; title: ; notranslate" title="">&lt;parameter name="FROMDATE" class="java.sql.Timestamp"&gt;
		&lt;defaultValueExpression&gt;&lt;![CDATA[new java.sql.Timestamp(System.currentTimeMillis()-2628000000)]]&gt;&lt;/defaultValueExpression&gt;
	&lt;/parameter&gt;
	&lt;parameter name="TODATE" class="java.sql.Timestamp"&gt;
		&lt;defaultValueExpression&gt;&lt;![CDATA[new java.sql.Timestamp(System.currentTimeMillis())]]&gt;&lt;/defaultValueExpression&gt;
	&lt;/parameter&gt;
</pre>

_notice how the default value is initialized to the current date, and the previous month!_

Then you can pass the parameter like this:

<pre class="brush: plain; title: ; notranslate" title="">ORDER_DATE between cast('$P!{FROMDATE}' as date) and cast('$P!{TODATE}' as date)
</pre>
