robsil Posted August 4, 2010 Share Posted August 4, 2010 I am passed in a date as a parameter.I want to display the first of the month for that date... can't figure out how to do it. Trying god awful ugly Expressions with Calendar class but ultimately I hit a void return type and can't get the expression going. Anyone able to point out a solution?Post Edited by robsil at 08/04/2010 01:29 Link to comment Share on other sites More sharing options...
abdon Posted August 4, 2010 Share Posted August 4, 2010 What do you mean by "the first of the month for that date"?If you mean the first day of the month, just statically use '1';But if what you mean is the fist three letters of the month, you can try setting your text-field pattern property to 'MMM'. Code: Post Edited by abdon at 04/08/2010 15:17 Link to comment Share on other sites More sharing options...
robsil Posted August 4, 2010 Author Share Posted August 4, 2010 Thx for the reply,The first of the month as in if I am passed in August 12, 1956, I would calculate the date August 1, 1956.January 12, 2005 would be january 1, 2005Dec 1, 1565 would be Dec 1, 1565etc. I am comfortable with the formatting of the display using Date Format variables... it's the date math of getting the date to reflect the 1st day of the month that is bothering me.To make things more complicated... I will need to do various other date calculations, such as 1st day of previous month, etc. etc. so I simply can't just put a '1' in the day field.Post Edited by robsil at 08/04/2010 18:43 Link to comment Share on other sites More sharing options...
abdon Posted August 4, 2010 Share Posted August 4, 2010 Maybe you could create a custom DateUtils class where you would put all the Calendar uglyness, all shielded by nice method signatures like Date DateUtils.getFirstOfTheMonth(Date date); Date DateUtils.getFirstOfPreviousMonth(Date date);Then you import this DateUtils into your report and use the methods on your expressions.For the moment, I can't think of anything better than Calendar for doing such calculations.Bruno AbdonPost Edited by abdon at 04/08/2010 16:09 Link to comment Share on other sites More sharing options...
robsil Posted August 5, 2010 Author Share Posted August 5, 2010 I am really trying to avoid using a custom class as the report will be ported to jasperserver and other environments when done and the less that has to go with it the better. I may just crack open Eclipse and see what sort of expressions I can create in 1 line if I get REALLY creative ;). 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