on 03-20-2015 6:33 AM
Hi
I am getting date format from source in 4 different formats(1.YYYY/MM/DD)(2.MM//DD//YYYY)(3.DD//MM//YYYY)(4.YY//MM/DD). In this which format will come don't no,but i have to send (YYYY/MM/DD) format at receiver.so how to handle this. if its UDF please provide me correct UDF.
Hi Bhagya,
Here is a UDF:
The code is below
for(int a=0;a<inp.length;a++){
int len = inp[a].length();
SimpleDateFormat input;
SimpleDateFormat otput = new SimpleDateFormat("yyyy/MM/dd");
Date date;
if(len == 10){
result.addValue(inp[a]);
}
else if(len == 9){
try{
input = new SimpleDateFormat("yy//MM/dd");
date = input.parse(inp[a]);
result.addValue(otput.format(date));
}
catch(Exception e){
e.getMessage();
}
}
else if(len == 12){
String year = inp[a].substring(inp[a].lastIndexOf("/")+1);
String res;
try{
input = new SimpleDateFormat("MM//dd//yyyy");
date = input.parse(inp[a]);
res = otput.format(date);
if(res.indexOf(year)>-1){
result.addValue(res);
}
else{
try{
input = new SimpleDateFormat("dd//MM//yyyy");
date = input.parse(inp[a]);
result.addValue(otput.format(date));
}
catch(Exception e){
e.getMessage();
}
}
}
catch(Exception e){
e.getMessage();
}
}
}
Testing:
Hope this helps,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
If you have this date 01/02/03.
How can you interprete this ? 01 feb 2003 or 02 Jan 2003 or maybe 03 feb 2001 or ...
This is not accurate at all. Maybe if you add something in your payload (a flag) to know in what case your UDF will format your date, otherwise you will never get a correct date format in many cases.
Best regards,
Sako
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, so I missed that it may come with any random format. I don't think any stable system works in that way. It has to be in some specific format. Or they need to send a KEY field within the message to identify in which format they generated the Date.
Regards,
Nabendu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bhagya,
It is not possible to write a programming logic for this requirement.
Let's say source system sends "06/11/2015". Is it Jun 11th OR 6th Nov? Is it dd/MM/yyyy or MM/dd/yyyy?
Please request source system to send consistent date format.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhagya,
You will to use a series of sandard function along withDate tranform functions to achieve this. You need to check the date format and based on that map he daa.
Let me know if you need any more inputs
Regards
Sriram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use DateTrans function available with Standard Mapping functions in PI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.