Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Date manipulation in expression builder
jimseconde
<p>Hi,</p>
<p> </p>
<p>I have a problem with converting strings to dates (and will probably have a problem converting back for display).</p>
<p> </p>
<p>Incoming strings for a column look like this:</p>
<p>01-2014</p>
<p>03-2014</p>
<p>10-2014</p>
<p> </p>
<p>I need BIRT to see these months as dates, then display them as 'Mar 2014', 'Oct 2014' etc.</p>
<p> </p>
<p>So, my thinking was getting the expression builder to "fake" the dates at binding level on the chart that will display the data: the code for the column looks like this-</p>
<p> </p>
<div>var input = dataSetRow["MONTH"];</div>
<div>var mon = input.substr(0,2);</div>
<div>var year = input.substr(3,4) + "-";</div>
<div>var day = '-01';</div>
<div>var concat = year + mon + day;</div>
<div>return new Date(concat);</div>
<div> </div>
<div>If it returned the correct date, I could then try and format the date as 'MMM yyyy' for display.</div>
<div> </div>
<div>I've tested this Javascript elsewhere, and there's no problem. But the data preview is coming back with a standard linux date (1970), so I can't work out where it's tripping up. (The column at data binding has been changed to Date not DateTime, and I added a new column binding which didn't work either)</div>
<div> </div>
<div>Any ideas please?</div>
<div> </div>
<div>Thanks</div>
Find more posts tagged with
Comments
micajblock
<p>You can use this code to create the date:</p>
<pre class="_prettyXprint">
new Date(row["DateString"].substr(3),BirtStr.left(row["DateString"],2) - 1,1)</pre>
<p>See attached design.</p>
jimseconde
<p>Absolutely perfect, thanks. Understanding the nested substring formatting now.</p>