on 06-22-2016 11:29 AM
Hi Professionals,
i want to get the difference between two timestamps or datetimes in my message mapping.
I am not good at Java, so i dont know how to achive this in an UDF.
My time format is eather hh:mm:ss or yyyy-mm-dd hh:mm:ss
The result should be a float in hours.
Eg: i have 10:00:00 and 10:30:00 so its 30min -> 0,5 hours
I would appriciate if someone could provide me the code or some help.
thanks!
Best regards
Enrico
Hello,
Try the below UDF
String result = "0";
long time = 0;
//long time = timeMillis / 1000;
String hours = Integer.toString((int)(time / 3600));
SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
try {
Date date1 = format.parse(time1);
Date date2 = format.parse(time2);
long diff = date2.getTime() - date1.getTime();
float f1 = diff;
float diffHours = f1 / (60 * 60 * 1000) % 24;
String Out= Float.toString(diffHours);
;result = Out;
} catch (Exception e) {
e.printStackTrace();
}
return result;
Time 1 and Time2 are the inputs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
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.