Error in comparing Date between two values "String was not recognized as a valid DateTime"

I am trying to create a condition in which date is returning from Abbyy. So if date is greater than 1 year so the DateisValid flag should be false otherwise True.
I am trying to compare date returning from Abbyy. But i am getting this error.

I am attaching the error and date field from Abbyy.
Compare Date.zip (11.5 KB)

Error from Studio:
dateerr

Date Field from Abbyy attachment:
image%20(1)

Abby is returning a string date. You have to convert it using Convert.ToDateTime() before you use it on your condition.
Where did you encounter the error? I tried your workflow and its working fine, all I did is to replace the value of RequestDate to a String date (“16/04/2018”) as I can’t use you in_argument.

yes when we try separately it is working but in the process it is not.
and in RequestDate i don’t need a hard-coded date in need from in_argument

What is the data type of your in_argument? I can’t try it because it is in other workflow, I can only ask


this is the data-type . Dictionary of string,string

Data type looks good. Where did you assign the string? I didn’t see that you assign it to a datetime variable base on the xaml that you shared.

I encountered this type of error when Abby return null values then assigning it to a DataTime variable

yes i am not sure about the string. can you please see my .xaml and also screenshot of date field from abbyy and create a working flow. as i am making a condition if the date from abbyy is more than 1 year the out_DateisValid flag will be true and if not it will be false

Where did you encountered the error? can you send a screenshot? The problem is not with the workflow that you shared, its working fine.

when i debug here is the error
sss

HI @zeshanm9

I tried running that assign activity. It works fine.

What’s the error that you are getting?

This error:
String was not recognized as a valid DateTime

The error is the same as the one you posted? There should be no error as your DateBeforeYear is in String Data type.

agree on @albert.yango mentioned. May be this is not there place you are getting the error. Can you run your code in Debug mode and see what happens? add a breakpoint to the very first activity. right click on the activity and click on toggle break point. Then run in the debug mode. Once the execution gets there, do the execution step by step to see where exactly the error occur…

@zeshanm9 If its okay to you to share the whole project please do so. so we can debug it ourselves. I’m really curious on what is happening

Hi @zeshanm9,

Hope this could help you. Checking your code you are not using the right pattern for the abby date.

Taking into account that the abby date has the following format “3/26/2019 10:37:02 AM” then you can use the following pattern to convert it to a dateTime variable:

Please, note that for getting the previous year for a date you can use Now.AddYears(-1) instead of Now.AddDays(-365).ToString(“dd/MM/yyyy”) and you will not have issues with leap years :slight_smile:

image

Please, find an example file 109894.xaml (5.7 KB)
and let me know!

Thanks and best regards,
Susana