cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF for Datum Timestamp

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

former_member194481
Participant
0 Kudos

Hi Experts,

If both the time and date are coming in the one field and how can we separate and add T to it

MM:DD:YY-T-HH:MM:SS

Kindly tell us how can we write the code for this.

BR,

Vijay Kumar

Former Member
0 Kudos

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

Former Member
0 Kudos

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