Dynamic date format convert to specific format

Hello,

I’m extracting a date from the filename and converting it to a specific date format mm-dd-yyyy however after running the job, it seems like the date on filename has different date formats. Is there a way to catch this? Like for two formats I can use the Tryparse date conversion.

Thanks

1 Like

Hi
May i know what was the dateformat that we obtain from that filename
can we have a sample filename if possible and the outcome expected as well
Cheers @wonderingnoname

Hi @Palaniyappan here’s the sample filename:

Name_DocumentType_20190220.pdf
Name1_DocumentType_09122019.pdf

I want to convert the date on to this format mm-dd-yyyy

1 Like

so for this
–assign this filename to a string variable named in_text
–use a assign activity and mention like this
out_date_Str = Datetime.ParseExact(Split(Split(in_text,“_”)(2).ToString,“.”)(0).ToString.Trim,“yyyyMMdd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MM_dd_yyyy”)
–now we can concatenate the value of the out_date_Str with a filename like this

Hopet this would help you
Kindly try this and let know for any queries or clarification
Cheers @wonderingnoname

won’t this work only for this format yyyyMMdd? I was hoping to have a function where it will work on any date format on filename

1 Like

Sorry for the delayed response
yah ofcourse it will work on for this format only
to make this robust we need to make sure that the filename has same set of dateformat at the end of the file name
–else we need to form too many probabilities to identify the date format
like this
–ddMMyyyy
–ddMMMyyyy
–MMyyyydd
–MMddyyyy
–MMMddyyyy
–MMddyy

it goes on right…so we need to make it robust with stable dateformat along the filename
which is actually a good practice. Ask the user to create the file with same dateformat at the end or if the process is generating that datetime format then its in our hand to include in our workflow design to handle that

Kindly correct me if i m wrong with the question
Cheers @wonderingnoname

Thing is, we can’t ask user to change the date format since these are already existing and we are talking about big files.

Thanks for the help @Palaniyappan. I’ll just create a condition once we identify which document types are using which format.

Cheers!

Sure
Cheers @wonderingnoname

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.