cancel
Showing results for 
Search instead for 
Did you mean: 

Date data type conversion into String data type

Former Member
0 Kudos

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!

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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);

henrique_pinto
Active Contributor
0 Kudos

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.

santhosh_kumarv
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Santhosh,

yes, your UDF is good, but "a" is an input parameter of type String, instead my ipotetical input parameter is of type "Date" and you know that it is not possible to change input parameter type of UDF.

Thanks!

Former Member
0 Kudos

Hi ;

any input to the UDF will be of string type.

If you pass it as date also it will convert it to sting .

try with

Current date --- UDF ---

Mudit

santhosh_kumarv
Active Contributor
0 Kudos

Hi

I hope that the Date will be received by the UDF as a string type argument.

Just giva a Try.

Does it reported any error.

Regards

Santhosh

Former Member
0 Kudos

Hi Mudit,

if what you said is true, then, why the output of any standard functions taht I can use that give currentDate as input, is SUPPRESS?

Thanks!

Former Member
0 Kudos

SUPPRESS is not because of the data type ,it might be because of the context of the date you are passing to the function .

SUPPRESS has nothing to deal with the data type

Mudit

Former Member
0 Kudos

Mudit,

I'm not stupid, I know this!!! I suppose that SUPPRESS is caused for a bad data type compatibility revealed by XI during runtime in mapping.

Thanks!

Former Member
0 Kudos

Hi;

see if you can get some resolution to this problem and please update the forum so that we all can learn.

Mudit

ravi_raman2
Active Contributor
0 Kudos

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

prateek
Active Contributor
0 Kudos

Use UDF

Regards,

Prateek

Former Member
0 Kudos

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

prateek
Active Contributor
0 Kudos

Use java date function.

Follow this

Regards,

Prateek