lukas.habermayr Posted July 17, 2017 Share Posted July 17, 2017 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. Link to comment Share on other sites More sharing options...
darth_fader Posted July 17, 2017 Share Posted July 17, 2017 What database environment are you working in? PostgreSQL, SQL Server, MySQL etc? Link to comment Share on other sites More sharing options...
darth_fader Posted July 18, 2017 Share Posted July 18, 2017 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 Link to comment Share on other sites More sharing options...
lukas.habermayr Posted July 18, 2017 Author Share Posted July 18, 2017 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 Link to comment Share on other sites More sharing options...
szaharia Posted July 18, 2017 Share Posted July 18, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now