Convert a specific Datetime format

I have received two types of date format in excel MM/dd/yyyy and dd/MM/yyyy.
I want the output should be MM/dd/yy
I tried the below code but got error - “value of 1-dimensional arry to string can’t be converted to string”.

DateTime.ParseExact(“12/06/2023”, {“dd/MM/yyyy”,“MM/dd/yyyy”}, System.Globalization.CultureInfo.InvariantCulture).ToString(“MM/dd/yy”)

@M_Rohan_Kumar_Senapaty

It is not advised to use these two formats at once as the dates might be read wrong…please try correcting from input

DateTime.ParseExact(“12/06/2023”, {“dd/MM/yyyy”,“MM/dd/yyyy”}, System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None).ToString(“MM/dd/yy”) is the correct way…but as specified usingb these two formats together is not advised

Cheers

@Anil_G
Thanks for the reply.

I encountered an error because I forgot to perform two actions:

  1. Import the System.Globalization namespace.
  2. This code can only be used in UiPath Windows projects and not in legacy projects, as legacy projects do not support multiple formats at once.

@M_Rohan_Kumar_Senapaty

Legacy also supports multiple formats at once

Cheers

1 Like

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