Jump to content

Using the current date in a query


pumaking

Recommended Posts

Hi,

we need to create a report in which all data from the current date is displayed. The field in the database which I compare it against has the following format: 20100701 and is a big decimal.

Now I created several parameters to find out the current date in Ireport:

currentdate: java.util.Date - new java.util.Date()

Now I convert it to a string with the following parameters:

currendate_year: java.lang.String - $P{currentdate}.getYear()+1900
currendate_month: java.lang.String - $P{Datumheute}.getMonth()+1
currendate_day: java.lang.String - $P{Datumheute}.getDate()

I don't know why but with the function getmonth I need to add a month because otherwise it's the month before the actual month.

With this parameter I connect the values to the decimal value as it is in the database:

currentdate_decimal: java.lang.String - $P{currendate_year} + "0" + $P{currendate_month} + $P{currendate_day}

However, as you can see, I have to add a "0" to the month, because for month july the function only returns "7" and not "07". The same problem do I have with the days, here I also get lack of the "0". For the months I could change that twice a year but for the days this work is too annoying.

Does anybody have an idea how to get rid of this problem in a better way?

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi...

there is always a simpler solution ...

to get the format YYYYMMDD from a sysdate try to use (for the String format)

new SimpleDateFormat("yyyyMMdd").format(new Date())

to get it in the BigDecimal format use:

new BigDecimal(new SimpleDateFormat("yyyyMMdd").format(new Date()));

to compare two BigDecimal use the equals() method and not the == operator.

 

leave us a feedback :)

_________________________________________

if it works... give me KARMA points please!    : ) 
_________________________________________

listening:  CSI - Io Sto Bene

"è una questione di qualità o una formalità
non ricordo più bene, una formalità
" (CSI)

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...