I have a project where I have to verify that extracted date from the web page. Extracted date is stored in data table. I am using the below condition and when I run this, I am getting error as String was not recognized as a valid DateTime and the condition is shown below:
Here MM/dd/yyyy is the format of input date string…depending on your string change the format…for hours and minute sand seconds hh:mm:ss : or / is general separation …that has nothing to do with the format
Give a try to this.
DateTime.ParseExact(AssigneeDocument.Item(“DatefromWeb”).ToString,{“M/d/yyyy”,“dd/MM/yyyy”,“d/M/yyyy”,“MM/dd/yyyy”,“MM/dd/yyyy hh:mm:ss”},System.Globalization.CultureInfo.InvariantCulture) > DateTime.Today.AddDays(-90)
Here {“M/d/yyyy”,“dd/MM/yyyy”,“d/M/yyyy”,“MM/dd/yyyy”,“MM/dd/yyyy hh:mm:ss”} is the array of possible input date format. If your input date fromat other than above mentioned then add that format to this list.
First of all, can you check (and share) content of AssigneeDocument.Item("DatefromWeb").ToString using WriteLine activity etc?
If it’s illegal date time style including empty string, it’s necessary to check whether valid date string in advance.
If there is extra white space, Trim method may work.
If it’s dd/MM/yyyy style, it’s necessary to use DateTime.ParseExact with format string"dd/MM/yyyy" for example.
Please use a log message before this and check the date format youa re getting or show it so that we can give you a correct format…
And also check if you are getting blank values sometimes if blank values are coming then we can detect them before hand and then use a condition so that the bot would not try to convert a blank value to date and fail