"How to Convert Dates in Various Unknown Formats to dd.MM.yyyy in UiPath?"

I have a data column containing dates in various formats, such as:

  • 11-12-2024 (e.g., dd-MM-yyyy)
  • 11-Nov-2024 (e.g., dd-MMM-yyyy)
  • 11-November-2024 (e.g., dd-MMMM-yyyy)
  • 1/2/2024 (e.g., d/M/yyyy)
  • And potentially other formats I may not be aware of.

I need to convert these dates to the dd.MM.yyyy format, but I don’t know the specific formats the dates are coming in. I need a solution that can automatically handle multiple date formats, without me needing to define each one explicitly.

How can I achieve this in UiPath, considering the flexibility of input formats? Is there a method to automatically detect and parse these various date formats, then convert them to the desired format (dd.MM.yyyy)?

Would using DateTime.TryParseExact with a list of potential formats work, or is there a better approach in UiPath?

Thanks in advance for any help!

Hi @Valigatla_Revathi,

You can maybe try this LINQ Query,
If(DateTime.TryParse(inputDate.ToString(), New DateTime()),
DateTime.Parse(inputDate.ToString()).ToString(“dd.MM.yyyy”),
String.Empty)

Hope this helps!

Hi @Valigatla_Revathi How are you?

Try do it below:

  1. create a variable as DateTime, such as “parseDate”
  2. Get your date that you want to convert
  3. use this expression in the IF activitie “DateTime.TryParse(dateString, parsedDate)”
    • This expression will try interpret date in various format
  4. use the assign activity with this command: newDateFormat = parsedDate.ToString(“dd.MM.yyyy”)

I hope it works to you :robot:

Hi @Valigatla_Revathi

Try using DateTime.Parse: DateTime.Parse is more flexible than DateTime.TryParseExact as it attempts to automatically detect and parse various formats without needing a predefined list.

Here’s how you can do it with invoke code:

Try
    Dim parsedDate As DateTime = DateTime.Parse(yourDateString)
    Dim formattedDate As String = parsedDate.ToString("dd.MM.yyyy")
Catch ex As Exception
    ' Handle parsing error if needed '
End Try
2 Likes

@Valigatla_Revathi,

Please refer this thread:

You can try it as an alternative solution

Dim formats As String() = {
“dd-MM-yyyy”, “dd-MMM-yyyy”, “dd-MMMM-yyyy”,
“d/M/yyyy”, “d-M-yyyy”, “M/d/yyyy”, “MMMM d,yyyy”
}

Regards,
Burçin

Hi @Valigatla_Revathi

Try this way,

Str variable = DateTime.ParseExact("Yourinput",{"dd-MM-yyyy","dd-MMM-yyyy","dd-MMMM-yyyy","d/M/yyyy"},System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None).ToString("dd.MM.yyyy")

If you have more input format means you can add in the array

Regards,
Gowtham K