on 07-12-2007 11:20 AM
Hi to all,
I want to take the current date in my graphical mapping and to substract "2" from this date. I use the "currentDate" function to get the current date and the "substract" function to substract the "2" value from my date. I format the date only with "yyyy" format model. My problem is that the currentDate function give me an output of type "Date" and not String, thus I'm not able to use any other functions, as "substract", that take a String value as input.
How can I solve this problem?
Thanks to all!
Let's just skip all this and take the simple way out. make a UDF with this import:
java.util.GregorianCalendar;
and this body:
GregorianCalendar cal = new GregorianCalendar();
int year = cal.get(GregorianCalendar.YEAR);
year-=2;
String years = ""+year;
return years;
here are all the functions to get the date in int form, which can easily be converted into Strings:
int era = cal.get(GregorianCalendar.ERA); // 0=BC, 1=AD
int year = cal.get(GregorianCalendar.YEAR); // 2002
int month = cal.get(GregorianCalendar.MONTH); // 0=Jan, 1=Feb, ...
int day = cal.get(GregorianCalendar.DAY_OF_MONTH); // 1...
int dayOfWeek = cal.get(GregorianCalendar.DAY_OF_WEEK);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gabriele,
I don't understand your problem.
The output of currentDate field is a string.
There are no other types in the input/output of graphical mapping fields other than String and String[] (array of strings).
For instance, try this: currentDate[yy] -> length -> targetField
Your output will be 2, as expected.
Regards,
Henrique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gabriele
Write a UDF like this.
public String rearrangedate(String a,Container container)
{
String date,month,year;
String result;
year=a.substring(0,4);
month=a.substring(4,6);
date=integer.parseInt(a.substring(6,8));
date=date-2;
result= datemonthyear ;
return result;
}
This UDF accepts the input in the YYYYDDMM format and also changes it into DDMMYY format.
Give a try with this.
Let me to know if this works as per your requirement.
Regards
Santhosh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gabrielle,
Try casting like this...
import java.util.*;
import java.text.*;
public class DateToString{
public static void main(String args[])
throws ParseException
{ String inDate = "07/12/2007";
SimpleDateFormat sdf = new SimpleDateFormat( "dd/mm/yyyy" );
Date dt = sdf.parse( inDate );
System.out.println(dt.toString());
}
}
That should fix your problem.....
Hope it helps
Regards
Ravi
Use UDF
Regards,
Prateek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Prateek,
yes, I know that I have to use a UDF, but the UDF takes as input parameters only objects of type String, instead, the funcion "currentDate" give me a "Date" object as output and this output will be the UDF input!
currentdate -> UDF -> substract...
have you understand the problem?
Thanks!
Message was edited by:
Gabriele Morgante
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.