tgrady Posted November 21, 2012 Share Posted November 21, 2012 Hi,I am trying to compare two date values in iReport and am unable to get it to work correctly. The below code is resident in the Text Field Expression property of a detail line. Some notes on the fields being used in the below staetment.($F{fieldA}.compareTo($V{fieldB}) == 0) ? "01/01/0001" : "fieldA"-> fieldA is a date field whose value will be overridden should it be equal to fieldB.-> fieldB is a date field (java.util.Date) that gets loaded via the following statement within it's variable expression property. - $P{initialDateCalendar}.set(1000, 00, 01) -> With the above in mind, the intent is to check if fieldA has a value of 01/01/1000 and if it does to set it to 01/01/0001. -> When I print the contents of fieldA and fieldB they both print out at 01/01/1000. Based on this I would expect the compareTo statement to yield an equal condition (== 0) and load fieldA with as value of "01/01/0001". With both fields being date fields, the compareTo iseems to the the correct comparison operator to use. Also, fieldA is a Date field (and not date-time).Am I missing something here? For what it is worth, I also tried .equals and == as comparison operators and they too yielded the same result as compareTo.Any help on this is greatly appreciated. Link to comment Share on other sites More sharing options...
Solution mdahlman Posted November 21, 2012 Solution Share Posted November 21, 2012 I would try something like this:( $F{Field1}.getTime() == $F{Field2}.getTime() ) ? "some string" : "another string"Note that your current example is closer to this:( some comparison ) ? "some string" : some_dateThat's bound to cause problems. Decide if you really want a String or if you really want a Date after the comparison is made. Link to comment Share on other sites More sharing options...
tgrady Posted November 30, 2012 Author Share Posted November 30, 2012 Thank you for your help on this. Link to comment Share on other sites More sharing options...
tgrady Posted November 30, 2012 Author Share Posted November 30, 2012 Thank you for your help on this. Link to comment Share on other sites More sharing options...
tgrady Posted November 30, 2012 Author Share Posted November 30, 2012 Thank you for your help on this. Link to comment Share on other sites More sharing options...
tgrady Posted November 30, 2012 Author Share Posted November 30, 2012 Thank you for your help on this. Link to comment Share on other sites More sharing options...
tgrady Posted November 30, 2012 Author Share Posted November 30, 2012 Thank you for your help on this. 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