String was not recognized as Valid DateTime

Hello,

I’m trying to get the difference of the dates using the below code but I’m facing an error.

Error message : String was not recognized as valid DateTime.

Actually this is working perfectly for another bot. Please help. Thank you

(DateTime.ParseExact(DateTime.Now.ToString(“yyyyMMdd”), “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture)-DateTime.ParseExact(PostingDate, “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture)).TotalDays
ErrorUipath.docx (120.1 KB)

@Pavan_Patke

Welcome back to our UiPath community.

Can you check once whether PostingDate value in the mentioned format (yyyyMMdd) or not.

Hello Sir, Yes. I just checked and its in the format “yyyyMMdd”.

Ex : 20180501

Hi @Pavan_Patke

Can you check the PostingDate as @lakshman suggested

(DateTime.ParseExact(DateTime.Now.ToString(“yyyyMMdd”), “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture)-DateTime.ParseExact(“20220222”, “yyyyMMdd”, System.Globalization.CultureInfo.InvariantCulture)).TotalDays

Format of the PostingDate is differ

Posting Date format should be 20220222

Regards
Gokul

@Pavan_Patke

Can you print both the dates separately and check both are in the same format or not. If possible can you please share screenshot of the output here.

Hello Lakshman sir,

I extracted both the dates and I found that there is a new row added into the application and date filed has gone a row down. Hence it was capturing a string instead of specific date.

Thank you for your time.

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