# Jasper plugin datetime

**URL:** <https://forum.servoy.com/t/jasper-plugin-datetime/12828>\
**Category:** Classic Servoy\
**Created:** [September 7, 2010, 8:43pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828 "2010-09-07T20:43:20Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [September 7, 2010, 8:43pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/1 "2010-09-07T20:43:20Z")

</div>

Hi,

Does anyone know what ‘Parameter Class’ a parameter within IReport must be when I transfer a Servoy (Javascript) datetime value through the parameter ‘parameters’ of runReport.  
I’m know getting JasperReport type errors when accessing the datetime parameter.

Or must I pass the datetime as a String ?

Regards,

---

<div class="post-metadata">

**Author:** ![ptalbot](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/ptalbot/32/4952_2.png) [@ptalbot](https://forum.servoy.com/u/ptalbot)\
**Post date:** [September 7, 2010, 11:35pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/2 "2010-09-07T23:35:46Z")

</div>

a datetime will be a java.util.Date

---

<div class="post-metadata">

**Author:** ![christineb1979](https://avatars.discourse-cdn.com/v4/letter/c/eb9ed0/32.png) [@christineb1979](https://forum.servoy.com/u/christineb1979)\
**Post date:** [September 8, 2010, 2:29am UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/3 "2010-09-08T02:29:03Z")

</div>

Where can i download this plugin? Thanks…

---

<div class="post-metadata">

**Author:** ![Andrei\_Costache](https://avatars.discourse-cdn.com/v4/letter/a/4af34b/32.png) [@Andrei\_Costache](https://forum.servoy.com/u/Andrei_Costache)\
**Post date:** [September 8, 2010, 6:13am UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/4 "2010-09-08T06:13:06Z")

</div>

> christineb1979:  
> Where can i download this plugin? Thanks…

[http://code.google.com/p/servoy-jasperr … loads/list](http://code.google.com/p/servoy-jasperreports-plugin/downloads/list)

Regards,  
Andrei

---

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [September 8, 2010, 6:33am UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/5 "2010-09-08T06:33:15Z")

</div>

> ptalbot:  
> a datetime will be a java.util.Date

Hi Patrick,

Thanks, but I need a **java.sql.Timestamp** because I use the datetime parameter in the report SQL query. A java.util.Date throws an error when the report SQL runs…  
Do you know a workaround in Servoy or in I-Report (JasperReport) ?

Regards,

---

<div class="post-metadata">

**Author:** ![stefbrt](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@stefbrt](https://forum.servoy.com/u/stefbrt)\
**Post date:** [September 8, 2010, 7:10am UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/6 "2010-09-08T07:10:35Z")

</div>

If the parameter has the type java.util.Date and your SQL looks like this:

```auto
SELECT * FROM test WHERE from_date >= $P{from_date}

```

it should work. If not an workaround would be to give the parameter the type string and set the servoy date with:

```auto
utils.dateFormat(date,'yyyy-mm-dd');

```

Regards,  
Stef

---

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [September 8, 2010, 12:12pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/7 "2010-09-08T12:12:42Z")

</div>

Hi Stef,

Thanks.

If I make the parameter type java.util.Date then I get following error within I-Report :

Caused by: java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp at saldi32balans\_1283947499421\_609992.evaluate(saldi32balans\_1283947499421\_609992:380) at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:182)

I’ll test the string option but I still need a java.util.Date for easy/nice displaying/printing of that date value itself…

Regards,

---

<div class="post-metadata">

**Author:** ![stefbrt](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@stefbrt](https://forum.servoy.com/u/stefbrt)\
**Post date:** [September 8, 2010, 1:13pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/8 "2010-09-08T13:13:46Z")

</div>

What JasperReport Version are you using?

Can you post you SQL?

Regards,  
Stef

---

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [September 8, 2010, 1:34pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/9 "2010-09-08T13:34:29Z")

</div>

I get the error with a simple sql … where entry\_date\>=$P(date\_range\_start) in I-report and when run from Servoy.

Verson 3.7.1

---

<div class="post-metadata">

**Author:** ![Thomas\_Parry](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Thomas\_Parry](https://forum.servoy.com/u/Thomas_Parry)\
**Post date:** [September 8, 2010, 2:37pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/10 "2010-09-08T14:37:35Z")

</div>

> I get the error with a simple sql … where entry\_date\>=$P(date\_range\_start) in I-report and when run from Servoy.

Should that not be curly braces : $P{date\_range\_start} ?

---

<div class="post-metadata">

**Author:** ![Thomas\_Parry](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@Thomas\_Parry](https://forum.servoy.com/u/Thomas_Parry)\
**Post date:** [September 8, 2010, 3:07pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/11 "2010-09-08T15:07:49Z")

</div>

You could always try converting the java.util.Date to java.sql.Timestamp either in the Jasper report or in Servoy before passing the parameter:

```auto
var date_range_start_as_timestamp = new java.sql.Timestamp(date_range_start.getTime())

```

---

<div class="post-metadata">

**Author:** ![jbader](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jbader](https://forum.servoy.com/u/jbader)\
**Post date:** [September 8, 2010, 7:27pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/12 "2010-09-08T19:27:01Z")

</div>

Hello,

When I pass in dates from Servoy that need to be used in SQL queries from within my jasper reports I do the following to the date…

```auto
new SimpleDateFormat("yyyy-MM-dd").format($P{DATE})

```

This will create a string from your date that will be formatted like ‘2010-09-08’.

If you use that string in your query, the DB will take care of ‘casting’ it for you to a timestamp (at least MySQL will)

Also note that to use a parameter in your SQL query you must make the parameter executable by adding a ‘bang’ after $P

```auto
$P!{PARAM}

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![lwjwillemsen](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/lwjwillemsen/32/4987_2.png) [@lwjwillemsen](https://forum.servoy.com/u/lwjwillemsen)\
**Post date:** [September 8, 2010, 7:54pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/13 "2010-09-08T19:54:33Z")

</div>

@Thomas : Yes, I did use {} (typo in message)  
@Thomas : Your _var date\_range\_start\_as\_timestamp = new java.sql.Timestamp(date\_range\_start.getTime())_ looks very promising ! I’m gonna test it… The java.sql.Timestamp parameters work very good in the sql query and you can use that parameter without de ! (bang). Thanks a lot !

@Jeff : Thanks for the info. I tested this afternoon already with $P\*\*!\*\*{start\_date} and when start\_date is a String parameter (‘yyyy-MM-dd’) then ![:D]( "Very Happy")

@Everybody : Thanks and consider problem solved…

Regards,

---

<div class="post-metadata">

**Author:** ![tgs](https://avatars.discourse-cdn.com/v4/letter/t/f19dbf/32.png) [@tgs](https://forum.servoy.com/u/tgs)\
**Post date:** [July 14, 2012, 6:28pm UTC](https://forum.servoy.com/t/jasper-plugin-datetime/12828/14 "2012-07-14T18:28:45Z")

</div>

Hi Lambert,

I’m currently couldn’t get the SQL query working with a date parameter for the jasperreport. It would be very nice if you could explain your parameter properties and Servoy functions if your solution is still running.  
In iReport (v. 4.6.0) I tried the parameter settings of $P{DATE\_FROM} and $P{DATE\_TO} as java.sql.Timestamp, java.util.Date and java.lang.String. I also tried the date formatting hints in this topic, but I always get errors and the report does not generate.

Regards,
