Type into - Date Field

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?

I have tried formatting the date using the code:

  • Convert.ToDateTime(DT.Rows(CurrRow).Item(“Cover_From”)).ToString(DateFormat)
  • System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()
  • Convert.ToDateTime(AccTrans.Rows(CurrRow).Item(“Cover_From”)).ToShortDateString()
1 Like

@Nelson.R
in general we can parse date strings with the following method:
DateTime.ParseExact(YourDateString,YourFormatAppliedForParsing, CultureInfo.InvariantCulture)

ensure following:
grafik

The value from excel is not mandatory the value in the datatable after a read range
But we can inspect while debugging:

  • set a breakpoint after read range
  • debug and get paused on breakpoint
  • inspect datatable content e.g. local panels
    OR
  • immediate panel: YourDataTableVar.Rows(0)(YourColNameOrIndex).toString

we would assume that also some time information will be found as well

Is there a way to determine what date format a user’s system has? Then I would be able to set the format.

@Nelson.R

You can check what format system is using

I know how to check but is there a way for the robot to check while it is running a workflow?

Don’t overcomplicate it with conversions.

Just split on the / and then reorder the 3 elements.

dateStringVar.Split("/")(1) + “/” + dateStringVar.Split("/")(0) + “/” + dateStringVar.Split("/")(2)

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.

Why do it that way? Why not set it to a known format, and just enter it in that format with your automation? Sounds like you’re overcomplicating it.

Would like to confirm if this is possible else I would have to change the format on each machine I run the process on.

This will tell you the system date format.

System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()

So I think if you have the date in a proper date variable, this would work…

myDateVar.ToString(System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern())

I am getting the error "disallowed implicit conversions from String to Integer

Put…

System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()

…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?

I got the format “M/d/yyyy”

I had put the myDateVar.ToString(System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()) into a message box

Do you have a variable named myDateVar? I just put that as a general example. You should use whateveryourvariableisnamed.ToString(…

And your variable needs to be a datetime.

Did not know the variable had to be a datetime, however, the date is printed out in the format,
“M/d/yyyy”

Hello Mr. Nelson.R,

Please mark as solved if your issue is sorted. I hope this helps:

  • Assign the date/time to a generic value like this:

    In_Date =  "31/05/2021"             ----> String
    
    In_Date_DateTime = DateTime.ParseExact(in_Date, "dd/MM/yyyy", Nothing) ----> Generic Value
    
    **You specify the datetime format here.**
    
  • Add the GenericValue inside the inbuilt activity Format Value. Choose Date Time and select your desired format.

  • (Optional) You can convert Generic Value back .ToString.

For reference:

Date_Conversion.xaml (6.1 KB)

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.

Found what I was looking for: Get the System Date Format - #5 by Kabeer

So for my case the only solution I could think of is to read a text file that has the system date format written in it.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.