Convert String Date to Date Object in BIRT
Virgil Dodson
E admin
<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>
<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
0
Categories
- All Categories
- 107 Developer Announcements
- 53 Articles
- 104 General Questions
- 141 IM Services
- 43 OpenText Hackathon
- 32 Developer Tools
- 20.6K Analytics
- 4.1K AppWorks
- 8.9K Extended ECM
- 898 Cloud Fax and Notifications
- 76 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 118 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management