on 07-08-2016 9:02 AM
Hi Experts,
The requirement is input will be an array of dates which might be of any format like DD/MM/YYYY , YYYY/MM/DD , DD-MM-YY, YY-MM-DD , etc something like these. Now I would like to write an UDF which accepts the input array of dates with whatever may be the input format & convert it to a format DD-MM-YYYY. Please help me to achieve the same. Thanks!
Rgds,
Naveen.
Hi Naveen,
If you are not able to force the business to stick with one date format to send then try to find out what are the different date formats they are going to send and add validation for each date format in your UDF.
Though this is not a good design as whenever new date format will come apart from those you have covered in your UDF its going to give you an error.
UDF will be something like -
Suppose business is going to send these 4 date formats - DD/MM/YYYY , YYYY/MM/DD , DD-MM-YY, YY-MM-DD
So first check the pattern-
String returnDate = null;
if(date.indexOf("/")!=-1) //date is your input date in UDF
{
String arr = date.split("/");
if(arr[0].length = 2)
returnDate = arr[0] + "-" + arr[1] + "-" + arr[2];
else if(arr[0].length = 4)
returnDate = arr[2] + "-" + arr[1] + "-" + arr[0];
}
Using this you will not be able to differentiate the difference between DD-MM-YY and YY-MM-DD. So fot these 2 your business need to send complete YYYY .
Thanks,
Apu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Naveen,
Please ask the business to define the format of the date else it is very difficult to understand from digits whether that is day , month or year.
Secondly are these dates related to current system date.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Inaki,
Thanks for your time! Actually the input date format is not constant but it will be dynamic.I mean the input format might be anything it doesn't remain constant or expected. Since the source of the data is from different senders in which all of them might not follow the same date format and it might keep changing. I believe in date transform function we could only change to required format only if we know the input date format right? Thanks!
Rgds,
Naveen.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
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.