on 07-15-2014 4:09 AM
Hi Experts,
Source data I am getting Date (MMDDYY) and Time(HHMM) and I need Target as MM-DD-YYYYTHH:MM:SS.
I can do it using DateTrans standard function but I need UDF for the requirement.
Please help me out.
Thanks
Hi Ram,
Please try below code:
import: java.text.SimpleDateFormat as like below
Copy below code:
Date date; | |
String output = ""; | |
SimpleDateFormat sdfSource = new SimpleDateFormat("MMddyy"); | |
SimpleDateFormat sdfDestination = new SimpleDateFormat("MM-dd-yyyy"); | |
SimpleDateFormat stfSouce = new SimpleDateFormat("HHmm"); | |
SimpleDateFormat stfDestination = new SimpleDateFormat("HH:mm:SS"); | |
try{ | |
date = sdfSource.parse(sDate); | |
String TDate= sdfDestination.format(date); | |
date = stfSouce.parse(sDate); | |
String Ttime = stfDestination.format(date); | |
output = TDate +"T"+Ttime; | |
}catch(Exception e){ | |
} |
return output;
Regards,
Krupa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay,
For this output MM:DD:YY-T-HH:MM:SS try below code
Date date; | |
String output = ""; | |
SimpleDateFormat sdfSource = new SimpleDateFormat("MMddyyHHmm"); | |
SimpleDateFormat sdfDestination = new SimpleDateFormat("MM:dd:yy"); | |
SimpleDateFormat stfSouce = new SimpleDateFormat("MMddyyHHmm"); | |
SimpleDateFormat stfDestination = new SimpleDateFormat("HH:mm:ss"); | |
try{ | |
date = sdfSource.parse(sDate); | |
String TDate= sdfDestination.format(date); | |
date = stfSouce.parse(sDate); | |
String Ttime = stfDestination.format(date); | |
output = TDate +"-T-"+Ttime; | |
}catch(Exception e){ | |
} |
return output;
Regards,
Krupa
code updated.. Message was edited by: Krupa Rao Atluri
Hi Ram
Please try the below code.
date and time (bold/italic) are the input variable names for the UDF.
DateFormat inDateFormat = new SimpleDateFormat("MMddyy");
DateFormat outDateFormat = new SimpleDateFormat("MM-dd-yyyy");
DateFormat inTimeFormat = new SimpleDateFormat("HHmm");
DateFormat outTimeFormat = new SimpleDateFormat("HH:mm:SS");
try {
String outputDate = outDateFormat.format(inDateFormat.parse(date));
String outputTime = outTimeFormat.format(inTimeFormat.parse(time));
String output = outputDate+"T"+outputTime;
} catch (ParseException e) {
return "Error";
}
return output;
Regards
Osman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.