• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

need to offset a date by intervals of 1 year

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello -

I am trying to design a report with multiple run dates (i.e. a series of subreports that use date parameters that offset from the prompted date parameters by an integer value of 1 - 4 years). I first tried to use the DATEADD function in my SQL statement but iReport tells me the function doesn't exist. So when that didn't work I tried to set up each offset date as a variable. I figured out that using groovy I could simply create a variable with the expression:

$P{rundate} - 365

but that won't work thanks to leap years. Any idea how I can offset a date using x number of years?

Thanks,

- Mike Perrone
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use java's GregorianCalendar and use set() method to set the date to any date of your choice, furhter you can add the year by using the add(gc.YEAR, 1) to change or offset the date of your choice. (note: gc is an instance of GregorianCalendar class)
 
Michael Perrone
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Samir. Can I trouble you to post an example of what that code would look like. I'm still struggling with the basics in java...

Thank you!

- Mike
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Perrone wrote:Can I trouble you to post an example of what that code would look like. I'm still struggling with the basics in java...


You'll learn more if you first try it yourself. Do you have a Calendar object of the date in question already? If not, in what form is the date, exactly?
 
Michael Perrone
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried... the problem is I just don't understand how java works. I've tried to teach myself using resources like "Head First Java" but to no avail. I need to use java to be able to create report variables using JasperReports (specifically using iReport as my development tool), but I can never get any of my questions answered in JasperForge's iReport forum.

I don't believe I have a calendar object of the date in question, but more fundamentally, I'm not sure what that means. At the highest level, I want the user to be able to input any date as a parameter and have Jasper translate convert that date into say the exact same month/day as last year. At lower levels though, I have no idea how to get there. The format of the date would be MM/dd/yyyy. When I try using the set() method in iReport, it tells me the method is not defined. But I don't know if the method is truly undefined, or if there is something I am doing wrong (like not including the right number of arguments or failing to use the set() method in conjunction with whatever else I should be using it with...)
 
Ulf Dittmer
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a bit confused. If you don't know Java, how do you propose to write and run code that invokes JasperReport (which is a Java API, after all)? Are you trying to create a Java desktop app for this, or a web app, or something else? Or is there an application already, and you're trying to adapt it? What are you starting with - just the report definition?
 
Michael Perrone
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No... I'm not creating or adapting anything... we use JasperServer to run/host our reports, and I've been using iReport to design them. They both link up to our MySQL database. So my only need for java is to write expressions for report variables.

With the simpler reports I've created thus far, I haven't needed to know much java as most of the report variables have been simple sums, counts, etc...

I appreciate your help Ulf in trying to figure out my postings... sadly my ability to explain is limited by my inability to comprehend!
 
samir singha
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, if you want to learn java basics. you may check the site www.jav apassion.com. Hope that will help you to learn java basics with IDE. Javaranch do not permit us to share code, so example of GregorianCalender you can find from thest links
http://www.java2s.com/Tutorial/Java/0040__Data-Type/CreatingGregorianCalendars.htm and http://www.java2s.com/Tutorial/Java/0040__Data-Type/SetwithGregorianCalendarYEARMONTHandDATE.htm

Check this examples and modify it suite your application.
 
Michael Perrone
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Samir!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic