How to change the date format in UIPath

I am trying to read the date from excel and store it in a variable by checking the format using Datetime.TryParseExact.
But it fails PFAS

I am using this condition to check

if(DateTime.TryParseExact(From, Valid_Date_Formats,System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimeStyles.None,DateTime_PlaceHolder))

Where From is the variable which holds the excel date and
Valid_Date_Formats has the date formats.

How can I solve this?

So does the excel column will be having different date format or one date format

Cheers @manzar_ali

I am not setting date format from excel, it has it owns by default according to region setting

Kindly try with this expression
DateTime.ParseExact(From, Valid_Date_Formats,System.Globalization.CultureInfo.InvariantCulture)

Cheers @manzar_ali

Facing this issue while applying the changes

1 Like

Yah I was about to tell that
Kindly change the variable name of it instead of From keep the name like in_date.ToString
As it is a keyword we will be getting this error
So that the expression be like this
DateTime.ParseExact(in_date.ToString, Valid_Date_Formats,System.Globalization.CultureInfo.InvariantCulture)

Cheers @manzar_ali

1 Like

The same issue, is it because of Valid_Date_Format as it is an array?

Oh is it an array
Then try with this expression
DateTime.ParseExact(in_date.ToString.Substring(0,10), “dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

Cheers @manzar_ali

This error occurs, also I need to compare the dates with multiple formats that’s why I am using the array

following are the values in the array

I think you are using this expression in a IF condition or in a WHILE LOOP like somewhere that takes in only Boolean variable in it
Is it so
If so we need to compare that with a DateTime value like
Your current expression > DateTime.Now
Kindly add any such condition with conditional operators we need

Cheers @manzar_ali

Thanks, I needed to change the format type and include times its working now