jongr Posted August 8, 2007 Share Posted August 8, 2007 I want to create an expression to calculate the number of months between two dates (preferably in groovy)and then multiply the result by a field value.Can anyone help - thanks Link to comment Share on other sites More sharing options...
jmurray Posted August 9, 2007 Share Posted August 9, 2007 Date calculations are a tricky thing. See http://www.xmission.com/~goodhill/dates/deltaDates.html and http://www.exit109.com/%7Eghealton/y2k/yrexamples.html for some examples. It's often easier to do this sort of thing in SQL where rudimentary date calculation methods are already available. In Oracle you can use the built in MONTHS_BETWEEN(Date1, Date2) function. MySQL has PERIOD_DIFF(P1,P2) but P1 and P2 are not Date values. They are date formatted integers of the form YYMM or YYYYMM. eg. SELECT PERIOD_DIFF(9802,199703) from dual; Link to comment Share on other sites More sharing options...
jongr Posted August 9, 2007 Author Share Posted August 9, 2007 Ok, I will try that, but before I do I will need to convert my Parameter date into YYYYMM so that I can use it in MySQL(The parameter is using the type java.util.Date)Can you suggest the best way ?Thanks Link to comment Share on other sites More sharing options...
nittu02 Posted August 9, 2007 Share Posted August 9, 2007 cant you set that using patterns in ireport?? Link to comment Share on other sites More sharing options...
jmurray Posted August 10, 2007 Share Posted August 10, 2007 In MySQL you would convert your date to 'YYYMMM' format using DATE_FORMAT(datefield,'%Y%c'). Turns out that PERIOD_DIFF function handles the two date serial numbers as numbers or strings. Have fun. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Link to comment Share on other sites More sharing options...
jongr Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks to jmurry, it works finenote: I had to change DATE_FORMAT(datefield,'%Y%c')to DATE_FORMAT(datefield,'%Y%m')so that I got two digit months Link to comment Share on other sites More sharing options...
jmurray Posted August 13, 2007 Share Posted August 13, 2007 Ah yes, very clumsy of me to miss that! Apologies. Link to comment Share on other sites More sharing options...
jazpiroz Posted September 7, 2007 Share Posted September 7, 2007 i need to calculate sumdate1 + 285 i cant do it, please give a tutorial or manual thanks a lot juan from uruguay Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now