String was not recognized as a valid DateTime error even after using DateTime.ParseExact

I am using
DateTime.ParseExact(getVal.ToString,“yyyy-MM-dd hh:mm:ss”,System.Globalization.CultureInfo.InvariantCulture)
to convert my generic variable type to DateTime.
getVal is my variable which I am getting from an excel file.

The value is in a format of yyyy-MM-dd hh:mm:ss
For eg - 2022-03-01 16:26:53

I am not able to resolve the error. Please help.

Thanks in advance.

1 Like

Hi @Nikhil_kathpalia ,

Could you give this a try?

image

DateTime.ParseExact("2022-03-01 16:26:53","yyyy-MM-dd HH:mm:ss",Nothing).ToString("HH:mm:ss")

image

DateTime.ParseExact("2022-03-01 16:26:53","yyyy-MM-dd HH:mm:ss",Nothing)

Kind Regards,
Ashwin A.K

1 Like

This just gives me a compiler error

Hi

Welcome to uipath forum

Try with this expression

Datatime.ParseExact(strinput.ToString.SubString(0,10).Trim, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture)

Output will be of DateTime

If you need in string of specific format

Stroutput = Datatime.ParseExact(strinput.ToString.SubString(0,10).Trim, “yyyy-MM-dd”, System.Globalization.CultureInfo.InvariantCulture).ToString(“dd/MM/yyyy”)

I want to suggest you one thing

You are almost right…

The only thing is timestamp

It’s in 24 hours format then hours should be in HH
But you have mention as hh in that DateTime expression

Change it to HH and give a try or
Try with the above suggestion

It should be fine

For more details on DateTime in uipath

Cheers @Nikhil_kathpalia

1 Like

HI @Nikhil_kathpalia

Try this expression

CDate(Inputstring).Tostring("yyyy-MM-dd HH:mm:ss")

Regards
Gokul

DateTime.ParseExact(“2022-03-01 16:26:53”,“yyyy-MM-dd HH:mm:ss”,Nothing) This actually works when I put the string on my own. But when I am getting the string from my excel file, it is not working

can you tell what I am possibly doing wrong?

Hi @Nikhil_kathpalia ,

We would ask you to Perform a Debug and Check the values of the Excel in the Immediate panel, or we could Check it with a Write Line Activity.

This way we can know if there are other formats as well included in the dates.

1 Like

Hi Can you share the sample Input Excel file @Nikhil_kathpalia

This actually worked, I changed hh to HH and it worked

Thanks a ton!!

Thankyou everyone who helped!! I was stuck at this since yesterday and this is my first time using UIpath community.

1 Like

Glad it got resolved
Cheers @Nikhil_kathpalia

1 Like

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