I'm trying to create a calculated field in a jasper domain which is a value of field is Datenum. I need to convert that datenum into a date format (1/1/16 or like this) while creating the calculated field.
I have tried by only changing the datatype from number to date. but it only gives something like this(1/1/70). I have attached screenshots below.
Are there any way to use this field as date field.
Conversion
First, you are not using any function to tell Jasper that you need a date. You have only set the data type to date. Since Java date began counting at 01.01.1970 this is the date you get.
The calculated field doesn't know how to interpret your data in the format 20160101
. It is possible to use a DomEL function called date
in the expression which interprets a date in ANSI format:
date('2016-01-01')
Nonetheless the format of the field SUBMITDATENUM
is different. The date function will not be able to interpret this. Unfortunately I am not aware if it is possible to provide a format in which the data is interpreted.
Datebase options
If you can change the format of the table structure, simply add another field or change the data format of the field (if feasible). Otherwise, you could add a database view which converts the field into a "real" date field.
This is the solution I would go for.
More options
There might be a possibility in version 6 with Groovy
since it can be used inline:
<field id="e.groovyEval" dataSetExpression="groovy('(5.0/6).toString()')" type="java.lang.String" />
So with the correct Groovy
function (which I haven't used yet - I don't know if variables can be inserted) this could help:
<field id="e.groovyDate" dataSetExpression="groovy('Date.parse(\'yyyyMMdd\', ASASMARTLAYER_PHWORDERSPAN.SUBMITDATENUM)')" type="java.lang.Date" />