Convert String Date to Date Object in BIRT

Virgil Dodson
Virgil Dodson E admin
edited July 28, 2021 in Analytics #1
<p><span style=\"font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;\">If your dates are coming out of a database as a String field, then it is difficult to format or use that date in a chart so you can easily convert the date string into a real date object. There are several places this can be done like directly on the table in a BIRT report, or in this example, I created a computed column.<br /><br />My date was coming in from the database as a String like this:<br />\"2007-10-17 00:00:00\"<br /><br />To convert this to a Date object,</span></p>
<ol>
<li><span style=\"font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;\">Create a new computed column in your data set.</span></li>
<li><span style=\"font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;\">Select \"Date\" for the Data Type</span></li>
<li><span style=\"font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;\">Add the following script modified with your field name</span></li>
</ol>
<blockquote>
<div class=\"xoopsCode\" style=\"border: 1px solid;\"><span style=\"font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;\">df = new Packages.java.text.SimpleDateFormat(\"yyyy-MM-dd\");<br />myDate = df.parse(row[\"your_date_field_name\"]);<br />myDate;</span></div>
</blockquote>
<p><span style=\"font-family: Verdana,Geneva,Arial,Helvetica,sans-serif;\">You should now be able to format the field as a date and use it correctly in expressions and charts.</span></p>
Warning No formatter is installed for the format ipb