on 02-07-2007 4:31 PM
Hi All,
How do I transform current date to format MM/dd/yyyy HH:mm:ss AM/PM?
I am able to get the format MM/dd/yyyy HH:mm:ss by using the standard date function. How do I get AM or PM to end of MM/dd/yyyy HH:mm:ss??
Thanx
Navin
Navin,
<u><b>you do not need any UDF for this</b></u>
you can do it using Current Date and specifing <b>hh:mm a</b> as the format.
You can use this format as well with DateTrans block if you need to translate a date and not to get a timestamp.
Have a look at this java doc, it could help: <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">Class SimpleDateFormat</a>
Hope this solve your problem
Kind Regards,
Sergio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Navin,
for sure, you can customize the output as you need.
In this case you need to specify the string <b>MM/dd/yyyy HH:mm:ss a</b>.
You can go through <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">Class SimpleDateFormat</a> to explore all the possible output format.
Kind Regards,
Sergio
Hi Navin,
I think you cannot achieve it using standard functions. You need to go for an User Defined Function.
Use an UDF after the DateTrans function. In that UDF you can append AM or PM to it. I think you need to add logic to find whether to append AM or PM. If you are unable to find the logic, post some sample values so that we can help you with the code.
Regards,
P.Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Navin,
How AM/PM is added? In the sample values given its in 24 hrs notation. Are u sure you want to add AM/PM to this notation? or U want to change this 24 hrs notation into 12 hrs and add AM/PM?
For converting into 12 hrs and appending AM/PM you can use this code:
input a:
int hr = Integer.parseInt(a.substring(11,13));
String appendVal = "AM";
if(hr > 12){
hr = hr - 12;
appendVal = "PM";
} else if(hr == 12){
appendVal = "PM";
} else if(hr == 00){
hr = hr + 12;
}
Sting finalVal = a.substring(0,11) + String.ValueOf(hr) + a.substring(13,a.length()) + appendVal;
return finalVal;
Regards,
P.Venkat
Message was edited by:
Venkataramanan
Navin,
I dont think your requirement is clear. But as far as I understood this is what you are looking for:
Currentdate --- Substring(12,13) --> Compare with Greater and constant 12 --> Then give this to IF condition. If this is true then Current Date + Concat + Constant PM else Current Date + Concat + Constant AM. It will work.
But only thing I am concerned here is with time. If your time is 14:59:21 then I think it should show as 02:59:21PM but not 14:59:21PM. My above logic works for this only. So please go through your requirement once again.
---Satish
u can do it by using datetransformation function in XI. u can use it while doing graphical mapping
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
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.