I have successfully read an excel file which contains 1 of its columns as a date.
There is no problem with reading and extraction of the values but once I save the value of a specific date to a variable, the value changes to “01-01-0001”
The date it I try to store to a variable is “[02/29/2020 00:00:00]”
The Activity I use to store it in a variable is Assign activity with the following code: var_DateIssued = Datetime.ParseExact(CurrentRow.Item(6).tostring, “MM-dd-yyyy hh:mm:ss”, System.Globalization.CultureInfo.InvariantCulture)
Hi @Parvathy, thanks for the reply.
Unfortunately I’m getting the same result. I believe the square bracket is only there in the input value as it is still a Object type.
DateTime variables don’t have a specific format though. You cannot create a DateTime that has the format "dd-MM-yyyy’ as the DateTime variable to format agnostic.
You can parse strings that are in that format to a date time, but once its parsed it no longer has a fixed format.
It looks like your Excel already read it as a Date Time, so you don’t need to convert to a string or dd-MM-yyyy format to give it to another variable unless you want it to become a string.
Hi, The date uses “/” but you used “-”. If you need to keep 24-hour format then use HH instead of hh format.
You should first clean the square brackets from the string and then parse it using the correct format:
var_DateIssued = DateTime.ParseExact(CurrentRow.Item(6).ToString.Trim(“”.ToCharArray), “MM/dd/yyyy HH:mm:ss”, System.Globalization.CultureInfo.InvariantCulture)
I believe this is a bug on the UiPath side or I’m doing the parsing incorrectly. All dates work correctly except for “02-29-2020,” which converts to “01-01-0001.”
For now I will pass it directly using CDate() as it retains the correct value and will just format it to string whenever I uses it in my automation.
Thanks to @Jon_Smith for the helpful information regarding DateTime – it really helped me in this case.
Its not a bug, this is core .NET code from Microsoft, its just because you are doing a conversion from Date>string>Date and its going wrong along the way. If you dont convert it and just keep it as a date time you won’t have an issue.