adiboing Posted July 12, 2011 Share Posted July 12, 2011 Hello guys,I use a Excel Datasource File, there are all string type fields.I had to change a date column in excel to the format yyyy-mm-dd to be able to convert it with a Textfield to a java.util.Date:Expression: new Date ($F{MyDate}.replace("-","/")) Now I am able to show the fieldoutput as a valid date formatting. BUT, now I compare to dates and substract those. I'm able to get the difference as an Integer with this Expression: new Integer(new Date($F{Datum TR 01}.replace("-","/")) - new Date($F{Bestelleingang}.replace("-","/"))) <---- this integer is also in a TextfieldKnow I have some Integer values into a Textfield. But I'm not able to SUM those integers together because I get an error when I try to write the same expression for the Integers in a Variable. EDIT: Here I add a picture for better understanding (Sry but somehow I wasn't able to include it directly)http://imageshack.us/photo/my-images/27/sumdate.png/Anybody can help me?Post Edited by adiboing at 07/13/2011 06:59 Link to comment Share on other sites More sharing options...
adiboing Posted July 13, 2011 Author Share Posted July 13, 2011 Nobody has an idea? Or is my explantation to bad to understand :(? Please help or just say something ^^ Link to comment Share on other sites More sharing options...
lknueve Posted July 13, 2011 Share Posted July 13, 2011 from your pic, are the cells in Excel showing "39 tag" or just "39"? I'm not sure what you're trying to do exactly, but if the cells only have "39" in them, then try in the variable syntax something like the following: $F{firstNumber}.intValue() + $F{secondNumber}.intValue() Link to comment Share on other sites More sharing options...
adiboing Posted July 15, 2011 Author Share Posted July 15, 2011 Nope thats not my problem :) Allright here you can see my Excel Datasource. The red marked area are date formated cells (yyyy-MM-dd) When I get this field via iReport its a normal stringtype field. So now I would like to get the difference of these dates in days. (Just to be clear: the word "Tage" in my first screenshot is a normal Static Label from iReport and this word is german and means days :D) The difference is 8 days and 39 days ;) BUT: I wasn't able to convert the datefield which is type string to a valid date format. It only works in a textfield with expression in my first post. So I'm able to convert the stringtype dates from the excel field in a textfield to a dateformat. And I'm able to substract those in a textfield. When I try to convert the datefields from stringtype to datetype with a Variable its not working, I recive errors. But I need the dates in a variable to work with them :( So long story short:Dates(stringtype) -> per textfield -> Dates(datetype) <-- workingDates(stringtype) -> per variable-> Dates(datetype) <-- not working, I get errors To calculate with the dates I need to have them in a variable :( Do you understand my problem now? Link to comment Share on other sites More sharing options...
adiboing Posted July 19, 2011 Author Share Posted July 19, 2011 Hey guys, please I need a solution about that but I'm not able to find it on my own :( I tried so many ways but nothings working...You can't tell me that nobody knows how to convert a string field from a datasource into a .data type... anybody should now this =/ Link to comment Share on other sites More sharing options...
pjamack Posted August 12, 2011 Share Posted August 12, 2011 Welcome to the Jasper World where it seems nobody really knows how to do simple reporting tasks. Many questions, very few real answers. I've tried similar things as you, not from Excel, but I call a function and get a Date stored as a string back. I've figured out how to subtract/add dates in a Parameter or Field, I've figured how to convert from String to date, but it's just at the variable or field display level. I haven't figured out how to convert string to Date, then subtract/add and group dates into Weeks, etc. At this point, after reading and asking questions, you have to assume Jasper is very limited in it's Reporting capabilities. That or nobody really knows how to use the product. Either way it's not a good thing. Support is limited. Questions never answered. Wish I could help, but all i Know is Java commons library can help you group things and break down dates, add/subtract dates, etc but only if it's a Date. Haven't been able to do it if it's a string and convert to Date. Variables converted from String to Date just use something like<variable name="theDate_1" class="java.lang.String"> <variableExpression><![CDATA[(($F{theDATE} != null && $F{theDATE}.length() == 10) ? $F{theDATE}.substring(0,2)+"/"+$F{theDATE}.substring(3,5)+"/"+$F{theDATE}.substring(6,10) : "")]]> </variableExpression></variable> there is an easier way, but that converted my String to Date. But it's still a string. It's not really a date. So It just converts it at a display level, not a useful level. 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