Home Analytics DevShare
The community of Analytics developers are invited to follow and participate in the developer network.
OpenText technical experts collaborate with supported customers and partners in the Magellan product area.

Convert String Date to Date Object in BIRT

VirgilVirgil AdministratorEM admin
edited October 19, 2007 in DevShare
<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>
<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>
<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>
<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>

Virgil Dodson
OpenText Analytics Developer Community

Sign In or Register to comment.