Date formatting - Long to Short


I’m extracting text from invoices. The challenge I have is that most of them have the long, textual, date format i.e.: “28 december 2018”

Could someone suggest (or better still, provide the code!) a means for me to convert this date into a short form date field (28/12/2018 or 28-Dec-2018) so that I can interface more easily with other platforms? I was hoping there would be a pre-existing function to do this but maybe there isn’t?


The DateTime class has a parse method.

DateTime dt = DateTime.Parse(“28 december 2018”);

Then, to format the date you can use the DateTime class toString method.

dt.ToString(“dd/MM/yyyy”) is equal to “28/12/2018”
dt.ToString(“dd-MMM-yyyy”) is equal to “28-Dec-2018”

Hi Daniel,

Thanks so much for coming back to me. I understand the code but am not quite sure how to put this into play when using the GUI of the UiPath Studio. Do you have a single step example project I could look at - a screenshot would do - which just shows what I need to do with the variables I have?

Below is where I’m up to:



First Assign:
invoiceDateString = “28 december 2018”

Second Assign:
invoiceDate = DateTime.Parse(invoiceDateString)

invoiceDateString is type String
invoiceDate is type System.DateTime

Just replace my variable names with what you are using for a String and a DateTime and then you can format the output string however you want. My log message activity will print “28/12/2018”.

Perfect! Thanks Daniel, declaring that variable with the correct type was the piece I was really missing there and that solved the puzzle. Nice one :+1:

1 Like

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