Issue: I am having trouble with a date formatting issue using parsing.
GOAL: Convert all dates in column G from yyyy/dd/MM to ddMMyyyy
Process:
I am using an excel application scope to read my file and create an output data table.
I then use a ‘for each row’ activity to loop through the rows. I am using an assign activity to create a variable “myDateTime” = Row(“Effective Date”).
I then use another assign activity to parse the date (DateTime.ParseExact(row(“Effective Date”).ToString,“yyyy/MM/dd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“ddMMyyyy”).
I then use a write range activity to write the data from the DTData table to the file specifying the column to return the values. I receive an error message "The string is not a recognized as a valid date/time.
@MF.RPA
the best is to debug the code and to inspect the datatable content, as it can differ from the visual presentation of the data in excel.
Issues for the not valid … exception could be:
empty values
the need of trimming the values
different datetime format within the datatable column give a try on MM/dd/yyyy HH:mm:ss
Also use the demo from below and do run an analysis job on the data. Just adopt the format as by your needs: FindNotMatchingDateFormatDates.xaml (6.8 KB)
I enabled preserve formatting and the application ran for 15 minutes and nothing happened.
I would also like to mention that the format in the excel file is appearing as yyyy/MM/DD but when I click format cells and select a different date format the values do not change / format into the newly selected format. Right now I have the dates formatted as “General”
The Excel recognized format is different than using DateTime.ParseExact(). But, it appears as though one of the values you are trying to convert is not in the yyyy/MM/dd format.
I would suggest always using an IF condition before converting to make sure you are converting a valid value…
You can use DateTime.TryParseExact() to check the value.
Then, what you can do is find out which value is not in the correct format. And, if there are values with end spaces, just add .Trim to the string. If you find that there are multiple date formats, you can use the format as an array (I think), like {“yyyy/MM/dd”,“yy/MM/dd”}.
One more thing, in your screenshot, you have the wrong format used, as compared to your number #3 point which is correct: DateTime.ParseExact(row(“Effective Date”).ToString,“yyyy/MM/dd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“ddMMyyyy”)
Hello,
Sorry for the delayed response, I had taken my computer in for service and it took a few days to get it back. I am still unable to figure this issue out. I tried to add an if activity and my assign activities in the THEN section but I received a complier error. Am I overlooking something basic here?
It looks like your quotation marks are the wrong character. Try replacing your quotes character with the quotation character again. Sometimes if you copy stuff from the forums, it does this.
Here is the solution for anyone still following this issue:
DateTime.ParseExact(EffectiveDate,“yyyy/MM/dd”,System.Globalization.CultureInfo.InvariantCulture).ToString(“MMddyyyy”)