ParseExact method throwing error

Date = Row(“Date1”).ToString

DateTime.ParseExact(Date1.ToString().Trim(),“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”) → Throws Format Exception

WHEREAS

DateTime.ParseExact(“03/12/2021”,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture).ToString(“dd-MM-yyyy”) → Gives the output

Not able to understand what is that I am doing wrong here? Somebody please help. Thanks in advance!

@Anand_Parkash_Aggarwal
Welcome to the forum

Find the following FirstAid in which analysis and possible fixing steps are described:
:ambulance: :sos: [FirstAid] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues - News / Tutorials - UiPath Community Forum

@Anand_Parkash_Aggarwal ,
Can you import this and check once : System.Globalization

image

If its not working can you please show us your input “Date1” by printing it somewhere?

Regards

Hi @Anand_Parkash_Aggarwal, welcome to the Community.

We can see that you are assigning Row(“Date1”).ToString to Date, but inside the query, you are using Date1.ToString().Trim(), instead of Date.

Also, it will throw an error if the variable data that you pass inside the query doesn’t match with the format dd/MM/yyyy.

Hope this helps,
Best Regards.

How to install the dependecy?

I am unable to find it under Manage Packages.

Output of Date1 is like this
image

@Anand_Parkash_Aggarwal ,

Not Manage Packages check below in “Imports”

Regards,

Added there. Still getting the same error.

Hi @Anand_Parkash_Aggarwal

Try this

Input date is of this format “MM/dd/yyyy”. So keep this format in the query.

DateTime.ParseExact(Date1.ToString().Trim(),"MM/dd/yyyy",System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MM-yyyy") 

Still not working. Same error

@Anand_Parkash_Aggarwal What error you are getting. Can u share the screen shot.

Hi @Anand_Parkash_Aggarwal

Can u share the input file which you are using. May be it has different date format.

DateTime.xlsx (9.1 KB)

Hi @Anand_Parkash_Aggarwal

Give a try to this

DateTime.ParseExact(Date1.ToString().Trim(),"MM/dd/yyyy 00:00:00",System.Globalization.CultureInfo.InvariantCulture).ToString("dd-MM-yyyy")
1 Like

@Anand_Parkash_Aggarwal
Exactly for such scenario the FirstAid was aligned. Did you run the analysis statements / inspection steps as described within?

Still same

@Anand_Parkash_Aggarwal

Check this workflow
Sequence9.xaml (7.6 KB)

Found the issue. It is a formatting issue due to Excel. Thanks for the help guys

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