Forum Discussion

JeffSm's avatar
JeffSm
Contributor
14 years ago

getting the PC's date format

Hi,



I have the need to know the PC's date format so that I can correctly enter a date field. Unfortunately, this can vary in different languages. Utilities.ShortDateFormat works, but I see that it's an obsolete property. Here's an example of what I'm doing in my script. Is there another way I should be doing this?



  if (Utilities.ShortDateFormat = "M/d/yyyy")

  {

    // Enter Patient DOB

    textBox = patientGB.textDateOfBirth;

    textBox.Keys("10151960[Tab]");

  }

  else if (Utilities.ShortDateFormat = "yyyy/M/d")

  {

    // Enter Patient DOB

    textBox = patientGB.textDateOfBirth;

    textBox.Keys("19601015[Tab]");

  }

  else if (Utilities.ShortDateFormat = "d/M/yyyy")

  {

    // Enter Patient DOB

    textBox = patientGB.textDateOfBirth;

    textBox.Keys("15101960[Tab]");

  }

4 Replies

  • Is there a property of the textbox that has the mask it is expecting?  For a similar problem, we queried the textbox to determine what format it was expecting and then formatted the data manually before entering it into the textbox.
  • I don't see any properties of textDateOfBirth that would tell me what the correct date format is. There is a get_DateFormat method though, but that only tells me that it's "short".



    Even though Utilities.ShortDateFormat is obsolete, is there some other reason I shouldn't use this? What replaced this?
  • Hi Jeff,

    Even though Utilities.ShortDateFormat is obsolete, is there some other reason I shouldn't use this? What replaced this?


    In TestComplete 7 and later, you can get the short date format specified in the computer's regional settings using the aqEnvironment.GetLocaleInfo method:





    But since your primary goal is to format a date, you can simply use the aqConvert.DateTimeToFormatStr method instead of checking the date format:



    // Enter Patient DOB

    var dt = aqDateTime.SetDateElements(1960, 10, 15);

    textBox = patientGB.textDateOfBirth;

    textBox.Keys(aqConvert.DateTimeToFormatStr(dt, "%x") + "[Tab]");

  • Hi Helen,



    Thank you for your help. That helped a lot!  I did have to make a minor adjustment though. Since patientGB.textDateOfBirth is actually a Janus calendar control, doing as you suggested was getting input correctly, but was not ending up correct in the application. I kept ending up with 10/16/2012.



    I changed this line from:

    textBox.Keys(aqConvert.DateTimeToFormatStr(dt,
    "%x") + "[Tab]");



    to:

    textBox.set_Value(aqConvert.DateTimeToFormatStr(dt,
    "%x") );

    textBox.Keys("[Tab]");



    Jeff