subtracting n days from java.sql.timestamp

0

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 java.util.date as type.

Any suggestions. 

lukas.habermayr's picture
Joined: Jun 28 2017 - 1:54am
Last seen: 2 days 1 hour ago

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

darth_fader - 5 days 20 hours 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 - 5 days 11 hours 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.

Thanks

 

 

lukas.habermayr - 5 days 7 hours ago

1 Answer:

0

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

DATERANGE("DAY-n").getStart()

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
1529
Joined: Sep 26 2006 - 8:06pm
Last seen: 5 days 4 hours ago
Feedback
randomness