jakehngo Posted August 1, 2017 Share Posted August 1, 2017 I have a student IDs and their date of births so I need to generate this final structure: StudentID(First Capital letter of birth month) and 2 digit day of birth:so student ID: 123456student's DOB: 6/7/2011here is what I want to see in the end: 123456J07Thanks. Link to comment Share on other sites More sharing options...
Raphaël Peguet Posted August 1, 2017 Share Posted August 1, 2017 I am using Jaspersoft Studio but it should be the same with iReport.In a text field you can use this expressionCONCATENATE("123456",LEFT(DATEFORMAT(DATE(2011,7,6),"MMM"),1),DATEFORMAT(DATE(2011,7,6),"dd"))[/code]Note that I am using DATE(2011,7,6) to generate the date 6/7/2011 but in your case I'd imagine you will use the value of a date field from your database so you can replace it by $F{DOB_field_name}CONCATENATE("123456",LEFT(DATEFORMAT($F{DOB_field_name},"MMM"),1),DATEFORMAT($F{DOB_field_name},"dd"))[/code] Link to comment Share on other sites More sharing options...
hozawa Posted August 2, 2017 Share Posted August 2, 2017 Assuming ID is type VARCHAR and DOB is type DATE, try the following expression:CONCATENATE($F{ID},LEFT(new SimpleDateFormat("MMM", Locale.ENGLISH ).format($F{DOB})),new SimpleDateFormat("dd").format($F{DOB})) Link to comment Share on other sites More sharing options...
jakehngo Posted August 2, 2017 Author Share Posted August 2, 2017 thanks for the help but I am having no luck still. Below are my fields and the expressions in how to get the field so not sure how to implement these fields into your code. Thanks STUDENTID= $F{localId}------this pulls in the student ids $P{shortDateFormat}.format($F{person}.getDob())-------- this formats and pulls in my dob field to show 1/5/2006 Link to comment Share on other sites More sharing options...
Raphaël Peguet Posted August 3, 2017 Share Posted August 3, 2017 Replying to your comment Jakehngo:You will need to replace "123456" by $F{localId} and "DATE(2011,7,6)" probably by $F{person}.getDob() considering this gives a Date. Also, you may use the SimpleDateFormat() method to control the local of the date as mentioned in a different answer. Link to comment Share on other sites More sharing options...
jakehngo Posted August 3, 2017 Author Share Posted August 3, 2017 Hi hozawa, I am using your suggestion and here is my code: CONCATENATE($F{localId},LEFT(new SimpleDateFormat("MMM", Locale.ENGLISH).format($F{person}.getDob())),new SimpleDateFormat("dd").format($F{person}.getDob())) but I getting this error message: Errors were encountered when compiling report expressions class file: 1. The method LEFT(String) is undefined for the type EMCSD45EMAIL45RPT_1501781853484_759547 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getValue()),LEFT(new SimpleDateFormat("MMM", Locale.ENGLISH).format(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob())),new SimpleDateFormat("dd").format(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob()))); <--> 2. The method LEFT(String) is undefined for the type EMCSD45EMAIL45RPT_1501781853484_759547 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getOldValue()),LEFT(new SimpleDateFormat("MMM", Locale.ENGLISH).format(((com.x2dev.sis.model.beans.SisPerson)field_person.getOldValue()).getDob())),new SimpleDateFormat("dd").format(((com.x2dev.sis.model.beans.SisPerson)field_person.getOldValue()).getDob()))); <--> 3. The method LEFT(String) is undefined for the type EMCSD45EMAIL45RPT_1501781853484_759547 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getValue()),LEFT(new SimpleDateFormat("MMM", Locale.ENGLISH).format(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob())),new SimpleDateFormat("dd").format(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob()))); <--> 3 errors Link to comment Share on other sites More sharing options...
Raphaël Peguet Posted August 7, 2017 Share Posted August 7, 2017 Hi,I wonder why you don't have the possibility to post a reply at the end of the page.Replying to your message:So here is my final code:CONCATENATE($F{localId},LEFT(DATEFORMAT($F{person}.getDob(),"MMM"),1),DATEFORMAT($F{person}.getDob(),"dd"))and here is the error that popsup:Errors were encountered when compiling report expressions class file:1. The method DATEFORMAT(PlainDate, String) is undefined for the type EMCSD45EMAIL45RPT_1501776653645_841955 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getValue()),LEFT(DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"MMM"),1),DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"dd"))); <-------->2. The method DATEFORMAT(PlainDate, String) is undefined for the type EMCSD45EMAIL45RPT_1501776653645_841955 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getValue()),LEFT(DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"MMM"),1),DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"dd"))); <-------->3. The method DATEFORMAT(PlainDate, String) is undefined for the type EMCSD45EMAIL45RPT_1501776653645_841955 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getOldValue()),LEFT(DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getOldValue()).getDob(),"MMM"),1),DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getOldValue()).getDob(),"dd"))); <-------->4. The method DATEFORMAT(PlainDate, String) is undefined for the type EMCSD45EMAIL45RPT_1501776653645_841955 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getOldValue()),LEFT(DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getOldValue()).getDob(),"MMM"),1),DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getOldValue()).getDob(),"dd"))); <-------->5. The method DATEFORMAT(PlainDate, String) is undefined for the type EMCSD45EMAIL45RPT_1501776653645_841955 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getValue()),LEFT(DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"MMM"),1),DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"dd"))); <-------->6. The method DATEFORMAT(PlainDate, String) is undefined for the type EMCSD45EMAIL45RPT_1501776653645_841955 value = (java.lang.String)(CONCATENATE(((java.lang.String)field_localId.getValue()),LEFT(DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"MMM"),1),DATEFORMAT(((com.x2dev.sis.model.beans.SisPerson)field_person.getValue()).getDob(),"dd"))); <-------->6 errors[/code]It seems that $F{person}.getDob() is not returning a value of format DATE and so is not able to be used by DATEFORMAT() function.Please make sure you have a DATE or convert your text into a date to be used in the DATEFORMAT.For example the function DATE() is taking 3 arguments or type number for the year, the month and the day and returns a DATE from it.Raphael Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now