Jump to content
We've recently updated our Privacy Statement, available here ×

formatting DOB into first letter of month (capital)


jakehngo

Recommended Posts

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: 123456

student's DOB: 6/7/2011

here is what I want to see in the end:   123456J07

Thanks.

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

I am using Jaspersoft Studio but it should be the same with iReport.

In a text field you can use this expression

CONCATENATE("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

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

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

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

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...