Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Birt Date Functions
rugaju
I am trying to use a calculated date field in BIRT where I can pass a date and it can determine the third Tuesday of that month based on the date passed. Is there a Java script function i can use in BIRT for this kind of calculation?
Find more posts tagged with
Comments
mwilliams
Hi rugaju,
If you pass a month and year to BIRT, you could figure out what day of week the first day of the month is, then calculate the date of the 3rd tuesday off of that value. Let me know if you have any questions on this.
thuston
This worked for me to get the 3rd Tuesday. There may be a simpler way, but I just computed it.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var first = new Date(BirtDateTime.year(row["ORDERDATE"]),BirtDateTime.month(row["ORDERDATE"])-1,1);
var tues = 2;
var fstday = first.getDay();
if ( fstday > tues )
first.setDate(1+(7-fstday+tues)+14);
else
first.setDate(1+(tues-fstday)+14);
first;
</pre>
<br />
Get the first day of the month and find out what day it is.<br />
If greater than desired day (tues), then add up the remaining days of this week plus the days until next desired (tues) [7-fstday+tues]. <br />
Else subtract the days before the first desired (Tues) [tues-fstday].<br />
Now you know the first desired/tuesday so add 14 to find the third.