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)
How to get a lexical duration from 2 dates
paskos
Hi,
I searched this forum and could not find the answer.
Sorry if a topic already covers my question.
I have a DB table containing 2 timestamp fields: startDate and EndDate.
I'd like to create a report showing for each line the duration between those timestamps in a human friendly way
ie. 3 hours 23 minutes and 3 seconds.
I want to use BirtDuration do do so but all its methods use String lexicalDuration as input.
I wonder, how can get a lexical duration from 2 dates ?
Thanks a lot
Pascal
Find more posts tagged with
Comments
Clement Wong
Pascal,<br />
<br />
Can you push this function down to your database?<br />
<br />
If not, you can either create a computed column in your Data Set, or add a new Data control that has the functionality like the code below. This is a quick stab using Javascript, and you should look into modifying to include years, and singular/plural noun forms of each duration (i.e. show "1 hour" instead of "1 hours").<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var timeDiff= row["myEndDate"].getTime() - row["myStartDate"].getTime();
var diffObj = new Object();
diffObj.days = Math.floor(timeDiff/1000/60/60/24);
timeDiff -= diffObj.days*1000*60*60*24;
diffObj.hours = Math.floor(timeDiff/1000/60/60);
timeDiff -= diffObj.hours*1000*60*60;
diffObj.minutes = Math.floor(timeDiff/1000/60);
timeDiff -= diffObj.minutes*1000*60;
diffObj.seconds = Math.floor(timeDiff/1000);
if (diffObj.days != 0)
diffObj.days + " days, " + diffObj.hours + " hours, " + diffObj.minutes + " minutes, " + diffObj.seconds + " seconds";
else if (diffObj.hours != 0)
diffObj.hours + " hours, " + diffObj.minutes + " minutes, " + diffObj.seconds + " seconds";
else if (diffObj.minutes != 0)
diffObj.minutes + " minutes, " + diffObj.seconds + " seconds";
else if (diffObj.seconds != 0)
diffObj.seconds + " seconds";
else
"No difference";</pre>
<br />
The attached example has a computed column that computes this string value.