How to convert string array to datetime array?


I am trying to convert a string array variable to a date time array variable, but cannot seem to work.
Thanks in advance!

Hi @kieranwong

Check this

Ashwin S

Hi @AshwinS2

That solution is converting the date format in string array. I am looking for converting string array to date time array. Or is there a way where i can extract datatable as date time format?

1 Like

May I know the date format of those strings in that array
Cheers @kieranwong



1 Like

can i have a example like
once after getting the datatble of this excel with read range activity and use a FOR EACH ROW activity and pass the datatable variable as input
–inside the loop use a writeline activity and mention like this
so that we could know the dateformat that excel gives us
kindly share that screenshot from output panel if possible

based on which we can easily convert that to a array of datetime

Sure here is the output

Create an Empty List of Datetime Format and for each Item in the String List Use an Assign and convert that to datetime Convert.ToDateTime(item.ToString) and add it to the datetime list

Sorry but what to do mean by create an Empty list of Datetime format. How do I do it ?

hope these steps would help you resolve this
–once after getting the datatable from read range activity use a assign activity like this
datetimearrayvariable = datatablename.AsEnumerable().Select(Function(a) Datetime.ParseExact(a.Field(of string)(“Holidays”).ToString.Substring(0,10),“MM/dd/yyyy”,System.Globalization.CultureInfo.InvariantCulture)).ToArray()
–where datetimearrayvariable is a array of Datetime variable

Cheers @kieranwong

1 Like

Its an Array of type DateTime

I have an error is there something wrong?

1 Like

you were almost done
kindly follow these steps to get this error out

Cheers @kieranwong

Now the script does not even work. Is there any other way?
Thanks for your help! @Palaniyappan

What was the error you were getting

user timeout

at which activity @kieranwong

The whole RPA script does not even start

can i have that excel file or a sample file if possible
Cheers @kieranwong

Hello Kieran,

Be careful regarding assuming the datatype within Excel. While Excel will present the data in a given way that may make you believe that it is a string, what UiPath actually gets back can be wildly different, especially with Timestamps.

In this case, what you’re seeing could be a Double instead. The reason I believe this is because actual string values are left aligned and the picture of your spreadsheet shows that the Day and Name are but the Holidays column is not.

I would suggest looking at DateTime.FromOADate if my suspicions are correct.