How to convert a string to a DateTime and change the format

Hello, I’m extracting a string from an Excel file, and I want to change the date format, but I keep encountering an error. The string is: “may 25, 2023”, and I want to convert it to: “25 mayo 2023” (changing the format and language). How can I achieve that?

@Carlubi
To achieve the desired date format and language conversion in UiPath, you can use the following steps:

  1. Read the date string from the Excel file and store it in a variable (let’s assume the variable is called dateString).
  2. Use the DateTime.ParseExact method to parse the dateString into a DateTime object using the source format (“MMMM d, yyyy”).

plaintextCopy code

Assign activity:
- Left side: date
- Right side: DateTime.ParseExact(dateString, "MMMM d, yyyy", System.Globalization.CultureInfo.InvariantCulture)
  1. Create a new string variable to store the formatted date.

plaintextCopy code

Assign activity:
- Left side: formattedDate
- Right side: date.ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("es-ES"))
  1. Now, the formattedDate variable will contain the date in the desired format and language (“25 mayo 2023”).

Make sure to adjust the culture settings (“es-ES”) to the appropriate language culture that you want to use. You can refer to the CultureInfo class in .NET for a list of available cultures and their culture codes.

By following these steps, you can convert the date format and language of the string from “may 25, 2023” to “25 mayo 2023” in UiPath.

1 Like

Hello @Carlubi You can Try below,

Log Message = CDate("may 25, 2023").ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("es-ES").DateTimeFormat)

1 Like

Thank you so much this works!!!

1 Like

Than you for the explanation!!!

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