Jump to content
We've recently updated our Privacy Statement, available here ×

How to compare date in database with current date


jonathanln

Recommended Posts

Hi, I read a lot on how to compare dates together but I still can't figure out how to solve my problem.

I have a column in my table filled with dates and I have to count how many  "dates in column" <= current date.

The format in the table is 'dd/mm/yyyy' and the type is DATE

==========================

My idea was to create a variable with "Calculation" set to "sum" and variable expression set to something like

Integer.valueOf( $F{table_date} <= sysdate ? 0 : 1)

but I haven't been able to use "sysdate" outside of the main report query and "<" doesn't seem to be accepted.

==========================

Thank you in advance for your help,

John

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

John,

 

Thanks for posting the solution for others!

 

Another way to address this is to do the date calculation in the query. Use something like this:
SELECT
   mydatefield as mydatefield,
   CASE WHEN mydatefield < sysdate THEN 1 ELSE 0 END as beforetoday
FROM
   ...

 

Then in iReport your variable is an easy-to-understand sum on the field "beforetoday".

 

And as a nit-picking detail, this sentence is not really correct: "The format in the table is 'dd/mm/yyyy' and the type is DATE". If it's a date column in the database then it does not have a format. There is a default display format based on server and/or client settings. But the underlying data is just a date with no formatting information attached.

 

Again, thanks for taking the time to post a solution. It helps to make the forums more useful to everyone.

 

Regards,
Matt

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...