I need to enter a date into a date field on an application. In the excel file the date format is saved as, “dd/MM/yyyy”, however, when it is entered into the application it is entered in the format, MM/dd/yyyy.
Note: the date format of the application changes based on the system’s date format.
Is there a way to format the date from the excel file to the same format as the system’s date?
@Nelson.R
in general we can parse date strings with the following method:
DateTime.ParseExact(YourDateString,YourFormatAppliedForParsing, CultureInfo.InvariantCulture)
ensure following:
The value from excel is not mandatory the value in the datatable after a read range
But we can inspect while debugging:
How the application works is that I can change it’s date format based on the systems date format. So I would like to know if there is a way to check what formatting is used to enter the date correctly into the application.
…into a Log Message and run your process. What does it give you?
What is the datatype of the variable you are using (before .ToString)?
Do you have the myDateVar.ToString(System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()) statement in an Assign, trying to assign it to an integer variable instead of a string variable?
Yes, you can only use the .ToString(format) expression on a datetime variable.
The resulting string should be in the format M/d/yyyy since that’s what the system date format is according to your test results.
There are also other system formats you can query, besides ShortDatePattern()
If you enter the full expression (myDateVar.ToString(System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern())) into the right side of an Assign, then delete the .ShortDatePattern() part, then type the . at the end, a menu will appear showing you the different options. Things like FullDateTimePattern or LongDatePattern can also be queried.