Jump to content

Parameter conversion from date to long


mulcamd

Recommended Posts

In my database, all dates are in seconds since 01-01-2001.

To have the user select an date I use an input control of the type date.

So after the user selects a date, this data parameter has to be converted from date to long and as long be used in the sql where.

In the query I use a second paramter of the type long. But this one seems to be always "null"

How to do that??

 

What I did was:

1e parameter: parameter is named $P{startDate}, type java.util.Date
This paramter is used in the input control.

2e parameter startDateLong, type java.lang.Long and
"Default Value Expression" as $P{startDate}.getTime() / 1000L

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

The problem is that $P{startDate} is not defined when you try to set the default value of $P{startDate}.getTime() / 1000L to parameter startDateLong.  Use a variable instead, and use BigDecimal rather than Integer:

 <variable name="startDateBD" class="java.math.BigDecimal">
  <variableExpression><![CDATA[new java.math.BigDecimal($P{startDate}.getTime() / 1000)]]></variableExpression>
  <initialValueExpression><![CDATA[new java.math.BigDecimal(0)]]></initialValueExpression>
 </variable>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...