Compare Two Dates With Differing Formats


I realize this question has come up multiple times but I have yet been able to solve it as my situation seems to be a little different than the previous posts.


1.) Extract String from Webpage that contains a Date (I already have this done)
2.) Parse out Date From String and Allocate to a Var (I already have this done)
3.) Take Date From String and Compare to Todays Date and Allocate Difference in Days to a Var (This is where I need help)


I am receiving this error message:

Assign : String was not recognized as a valid DateTime

I am using this code in an ‘Assign’ activity to convert string to DateTime which is popping up error:

DateTime.ParseExact(vDueDate_String, “dd-MM-yyyy”, CultureInfo.InvariantCulture)

Potential Reasons:

1.) The Date String I am passing into this (‘vDueDate_String’) is in a ‘MM/dd’yy’ format…this is the format that is in the string that I am parsing out.

Thus, do I need to change the format of this var to the ‘dd-MM’yyyy’ format before putting into the ‘Compare Date’ activity?

Any and all help would be much appreciated.

Hey @AutomateWork

Have you gone through with this thread?


1 Like

Thanks so much!

I apologize for repost question but I genuinely thought inquiry was different.

Its ok pal @AutomateWork

Better to search with keywords :slight_smile: you will get more accuracy :slight_smile: but nevermind i also remember this because i have posted for the same otherwise it is difficult sometime to know the posts which already exists :slight_smile:

Thanks for advice!

Actually, the solution does work but not as intended ;/

So this particular use case…the Due Date was 11/1/10 (Thus a long time ago)

However, when I ran the automation it only gave me back 5 Days as difference.

This is because it is only taking into account the days, not years as well.

IS there a workaround for this?

This might be the format…of datetime at your system :slight_smile:

to check date format on your system write line Now.Date.Tostring and check.

Use TotalDays instead of Days.

like this:

Convert.ToString((Convert.ToDateTime(“10/12/2017”)- Convert.ToDateTime(“10/12/2016”)).TotalDays) //365

Or if you want in Year Month things then you can perform some operations. Let me know…



Worked like a charm!

Thanks again.