Date function compile problem


I have a report (javabean collection datasource) which uses a date function - DATEFORMAT($F{meetingDate},"EEEE dd MMMM yyyy").  The report runs fine in eclipse and if I remove the function it runs properly through java.  

With the function I get the following errors though 

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method DATEFORMAT(Date, String) is undefined for the type Product_1428678178249_632342
                value = DATEFORMAT(((java.util.Date)field_productDate.getValue()),"EEEE dd MMMM yyyy"); //$JR_EXPR_ID=10$
2. The method DATEFORMAT(Date, String) is undefined for the type Product_1428678178249_632342
                value = DATEFORMAT(((java.util.Date)field_productDate.getOldValue()),"EEEE dd MMMM yyyy"); //$JR_EXPR_ID=10$
3. The method DATEFORMAT(Date, String) is undefined for the type Product_1428678178249_632342
                value = DATEFORMAT(((java.util.Date)field_productDate.getValue()),"EEEE dd MMMM yyyy"); //$JR_EXPR_ID=10$
3 errors

After searching I have tried 

1) dwonloading and adding jasperreports-functions-6.0.0.jar to the build pah

2) alterring the POM to include commons-lang-2.6.jar and excluding it from the Jasper dependency (see below).

this hasn't made any difference.  Can anyone help ?


benkdishman's picture
Joined: Apr 5 2015 - 7:25am
Last seen: 5 years 7 months ago

1 Answer:


DateFormat is an abstract Java class. You need to use one of the static factory methods through getDateInstance() instantiation to format a date for the current Locale, such as


To format your productDate field from SQL query resultant data set into "EEEE dd MMMM yyyy" pattern in the report display, you will need to first create a SimpleDateFormat object using your display pattern (new java.text.SimpleDateFormat("EEEE dd MMMM yyyy") then use this SimpleDateFormat object to format your date field .format($F{productDate}).

But ....... Why? JasperReports already has the build Date format function to do this for you. You can simply display your productDate field in the report with  "EEEE dd MMMM yyyy" pattern:


           <textField pattern="EEEE dd MMMM yyyy">

Please give a try and this should work for all SQL date/time/timestamp types (and save you a lot of trouble by coding the date formatter yourself).

tchen's picture
Joined: Feb 27 2008 - 7:33am
Last seen: 10 hours 8 min ago

Not quite sure I understand where I would put the java code for the formatting (in the expression editor, or would I have to do that bit in Java code and pass it through ?). I guess this is a moot point though as your simple solution works fine (apologies I hadn't noticed this section in the editor, I'm still very new to Jasper). Thanks again.

benkdishman - 6 years 6 days ago

JasperReports is a Java application and your report design will be converted and compiled as a Java executable to run the report. Therefore, expressions in the report design will accept valid Java class method as long as it produces a non void object.

tchen - 6 years 4 days ago

Im trying to get the difference in years between two datetimes and same as benkdishman I encounter similar error. I dont quite understand what you're trying to say tchen. Im a newbie here and not being able to use functions that are supposed to be built in is frustrating.

sabmoonie - 5 years 8 months ago