subtracting n days from java.sql.timestamp


Hi all,

I'm trying to substract n days from the current date. I'd like to use this in my query to filter results older than NOW()-n days.
The column in the database is of type timestamp. I guess it's best to do this i the query but I haven't found any working solution yet...
All the other threads are using as type.

Any suggestions. 

lukas.habermayr's picture
Joined: Jun 28 2017 - 1:54am
Last seen: 3 weeks 5 days ago

What database environment are you working in? PostgreSQL, SQL Server, MySQL etc?

darth_fader - 2 months 1 week ago

This is fairly straightforward, but if you want to keep it in the query (I strongly recommend that approach, you're on the right track), but it depends on the DB environment you're using. Each flavor of DB has it's own date/time functions for date manipulations

darth_fader - 2 months 1 week ago

It's an specific db environment from a company. The sql language used is SQL-92.
Any other solutions (e.g. using parameters) are ok with me.




lukas.habermayr - 2 months 1 week ago

1 Answer:


You could use the built-in DATERANGE() function in an expression like this:


where n is the number of days to be substracted.

To make this work, you need to place the jasperreports-functions.jar in your app classpath.

shertage's picture
Joined: Sep 26 2006 - 8:06pm
Last seen: 2 hours 5 min ago