Datetime.ParseExact : String was not recognized as a valid DateTime

Hi,

I am facing problem while executing a Datetime.ParseExact in the assign activity. But i when print it in message box using hardcoded value same syntax is working fine.

Input(Excel)
image

Assign:

row(“Datetime Parse(Out)”) = Datetime.ParseExact(row(“Out”).ToString,“HH:mm:ss”,system.globalization.cultureinfo.invariantculture).ToString(“h:mm tt”)

Message Box:

Datetime.ParseExact(“11:15:00”.ToString,“HH:mm:ss”,system.globalization.cultureinfo.invariantculture).ToString(“h:mm tt”)
image

Error:
DateTime ParseExact: String was not recognized as a valid DateTime

I have referred various posts and microsoft docs, still I am unable to figure what I am missing here…

Please assist.

@prasath17

Check as below
Convert Date & Time Format Tutorial
Tutorial : How to Calculate difference between two Time Values using UiPath - #2 by system

Hope this helps you

Thanks

1 Like

@Srini84 - I have already watch your video. What I am doing here is little different and my goal is to use Datatime.ParseExact…

@prasath17

Okay, you want to change the format of the time using DateTime.ParseExact rite?

Thanks

Yes…that is correct.

On the second video link, using DateDiff you can usely find out the difference between date or time…

@prasath17

Try this below

DateTime.ParseExact(row("Out").ToString,“MM/dd/yyyy HH:mm:ss”,System.Globalization.CultureInfo.InvariantCulture).Tostring("HH:mm tt")

Hope this helps you

Thanks

Thanks… @ksrinu070184
Nope…it didn’t work.i have already tried all the variations…But the same combination is working with Messsagebox…

There should be something to do with Excel…

@prasath17
hava a look on this xaml:
FindNotMatchingDateFormatDates.xaml (6.8 KB)

After modifying it to your scenario it can be used for identifying the non parseable dates.
In combination with excel check following:

  • blank after dates, fix with trim
  • format in datatable different as visually in Excel - inspect while debugging and adopt the format
  • empty cells - check and handle as by your needs
2 Likes

@prasath17

Check the output and write back to the excel
image

Hope this is what you required, rite?

Workflow
Main.xaml (9.7 KB)
Date.xlsx (7.3 KB)

Hope this helps you

Thanks

1 Like

Thanks @ppr … Sure I will take look.

While debugging I found that cell value is different than “Actual cell value” - As shown below

image

Could this be a problem?

just run the analyzer xaml and we have a clear list of all issue date strings

1 Like

@Srini84 - wow…this did it the trick…

My syntax was wrong, i was missing ‘MM/dd/yyyy’. Thank you so much…

1 Like

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