Jump to content

BIRT Developer Center Download


Photo
- - - - -

Birt Date Functions


  • Please log in to reply
2 replies to this topic

#1 rugaju

rugaju

    Junior Member

  • Members
  • PipPip
  • 15 posts

Posted 23 September 2010 - 12:56 PM

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?

#2 mwilliams

mwilliams

    BIRT Guru

  • Administrators
  • 14175 posts

Posted 24 September 2010 - 05:53 AM

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.
Regards,

Michael Williams

Actuate Corporation – The BIRT Company™

Instantly add interactivity, scheduling, sharing, live Excel exporting, and JavaScript integration capabilities to your BIRT application with the new, free BIRT server, BIRT iHub F-Type.
 
Find me on:
Twitter
Facebook
Blog

LinkedIn
 
Email me:
Google: mwilliams.actuate@gmail.com

#3 thuston

thuston

    Member

  • Members
  • 481 posts

Posted 24 September 2010 - 06:09 AM

This worked for me to get the 3rd Tuesday. There may be a simpler way, but I just computed it.

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;

Get the first day of the month and find out what day it is.
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].
Else subtract the days before the first desired (Tues) [tues-fstday].
Now you know the first desired/tuesday so add 14 to find the third.