Define own date intervals with startDate and endDate in a new variable

Hi everyone,

I am struggling with a date calculation to define my own range for a bar chart series.

My dynamic dates are parameters the timestamp parameters "timestamp1", "timestamp2", "timestamp3", wheras I want to create the intervals

interval1: days between "timestamp1" and "timestamp2"

interval2: days between "timestamp2" and "timestamp3".

What is the expression that I have to add to my variables in order tohave two time intervals for my bar chart series? I am completely lost with this issue...

 

Thanks!

natalie.koop's picture
Joined: Dec 9 2013 - 3:20am
Last seen: 9 years 9 months ago

2 Answers:

To do date calculations inside a report you can use a calendar instance as a parameter, is easier to explain with a sample. Check the attached report. It takes 2 parameters, Date From and Date To, and uses a calendar instance (see parameter 'cal') to do all sort of date calculations.

Attachments: 
AttachmentSize
Binary Data datesstandard_jrxml.jrxml10.65 KB
marianol's picture
17620
Joined: Sep 13 2011 - 8:04am
Last seen: 4 years 12 months ago

   

I solved the problem with a complete different approach. So if anyone may want to add time intervals into an iReprt chart, consider the following:

I summed up the download numbers from each time interval in my SQL query. Like that:

    SELECT 
    SUM(CASE WHEN Downloads.ExtractDate BETWEEN "$P{myTimestamp1}" AND "$P{myTimestamp2}" THEN Downloads.Downloads ELSE 0 END) AS Sum1,
    SUM(CASE WHEN Downloads.ExtractDate BETWEEN "$P{myTimestamp2}" AND "$P{myTimestamp3}" THEN Downloads.Downloads ELSE 0 END) As Sum
    FROM aacdb.Downloads


In iReport, I created a bar chart using the following Chart Series Information (*right click on chart* -> *Chart Data* -> *Details*):

**SERIES 1**

Series Expression

    (new SimpleDateFormat("dd.MM.yy").format($P{myTimestamp1})) + " - " + (new SimpleDateFormat("dd.MM.yy").format($P{myTimestamp2}))

Category Expression

    $F{Name}

Value Expression

    $F{Sum1}


**SERIES 2**

Series Expression

    (new SimpleDateFormat("dd.MM.yy").format($P{myTimestamp2})) + " - " + (new SimpleDateFormat("dd.MM.yy").format($P{myTimestamp3}))

Category Expression

    $F{Name}

Value Expression

    $F{Sum2}

natalie.koop's picture
Joined: Dec 9 2013 - 3:20am
Last seen: 9 years 9 months ago
Feedback
randomness