skyman
skyman

Reputation: 2335

How to count records with hour within range

I have a Jasper Reports requirement to count the number of records for which the hour component of a date field is within a range from 18:00 hours to 06:00 hours. I have created a summed variable with the following structure:

new Integer( ( ((new org.joda.time.DateTime($F{CCDateDis}).getHourOfDay()) > 18) &&
               ((new org.joda.time.DateTime($F{CCDateDis}).getHourOfDay()) < 6)
) ? 1 : 0)

Where $F{CCDateDis} is a Date() object.

The variable sum always returns '0' even though I know that there are records that fall within this range. Is there something that I am missing here?

Upvotes: 0

Views: 56

Answers (1)

Bohemian
Bohemian

Reputation: 425083

Reverse the comparisons.

Your logic is basically:

x > 18 && x < 6

This is mathematically always false - there is no number that is both greater than 18 and less than 6.

Change the logic to:

x <= 18 && x >= 6

Upvotes: 2

Related Questions