Setting DateTimePicker Time in Desktop Windows Applications

Applies to TestComplete 15.45, last modified on December 01, 2022

While testing combo box controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

You can set time in the DateTimePicker control by doing one of the following:

  • Assign a value to the wTime property of the Win32DateTimePicker object. During the test run this object is automatically associated with DateTimePicker controls whose class names are listed in the Object Mapping options of the project. wTime specifies the time selected in the DateTimePicker control. This property is useful only if wIsDateFormat is False and wChecked is True.

    You can assign a value to the wTime property using a string or a specific value.

    If you use a string to specify a time value, then the string must contain the time in the format that corresponds to the Regional Settings used on your computer.

    Below is an example that demonstrates how you can select time in the DateTimePicker control that is displayed on the fourth page of Windows Scheduled Task Wizard (this page is shown for the tasks that are supposed to be executed only once):

    JavaScript, JScript

    function Main()
    {
      var DateTimePicker;

      // Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1);

      // Set the time
      DateTimePicker.wTime = "11:11:11 PM";
    }

    Python

    def Main():
    
      # Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1)
    
      # Set the time
      DateTimePicker.wTime = "11:11:11 PM"

    VBScript

    Sub Main
      Dim DateTimePicker

      ' Obtain the DateTimePicker control
      Set DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1)

      ' Set the time
      DateTimePicker.wTime = "11:11:11 PM"
    End Sub

    DelphiScript

    procedure Main;
    var DateTimePicker;
    begin
      // Obtain the DateTimePicker control
      DateTimePicker := Sys.Process('Explorer').Window('#32770', 'Scheduled Task Wizard', 1).Window('#32770', '', 1).Window('SysDateTimePick32', '', 1);

      // Set the time
      DateTimePicker.wTime := '11:11:11 PM';
    end;

    C++Script, C#Script

    function Main()
    {
      var DateTimePicker;
      
      // Obtain the DateTimePicker control
      DateTimePicker = Sys["Process"]("Explorer")["Window"]("#32770", "Scheduled Task Wizard", 1)["Window"]("#32770", "", 1)["Window"]("SysDateTimePick32", "", 1);

      // Set the time
      DateTimePicker.wTime = "11:11:11 PM";
    }

    You can do the same using the SetTimeElements method of the aqDateTime object. This method returns a specific value calculated from the given hour, minute, second and millisecond.

    Here is an example:

    JavaScript, JScript

    function Main()
    {
      var DateTimePicker;

      // Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1);

      // Set the time
      DateTimePicker.wTime = aqDateTime.SetTimeElements(11, 11, 11);
    }

    Python

    def Main():
    
      # Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1)
    
      # Set the time
      DateTimePicker.wTime = aqDateTime.SetTimeElements(11, 11, 11)

    VBScript

    Sub Main
      Dim DateTimePicker

      ' Obtain the DateTimePicker control
      Set DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1)

      ' Set the time
      DateTimePicker.wTime = aqDateTime.SetTimeElements(11, 11, 11)
    End Sub

    DelphiScript

    procedure Main;
    var DateTimePicker;
    begin
      // Obtain the DateTimePicker control
      DateTimePicker := Sys.Process('Explorer').Window('#32770', 'Scheduled Task Wizard', 1).Window('#32770', '', 1).Window('SysDateTimePick32', '', 1);

      // Set the time
      DateTimePicker.wTime := aqDateTime.SetTimeElements(11, 11, 11);
    end;

    C++Script, C#Script

    function Main()
    {
      var DateTimePicker;
       
      // Obtain the DateTimePicker control
      DateTimePicker = Sys["Process"]("Explorer")["Window"]("#32770", "Scheduled Task Wizard", 1)["Window"]("#32770", "", 1)["Window"]("SysDateTimePick32", "", 1);

      // Set the time
      DateTimePicker.wTime = aqDateTime["SetTimeElements"](11, 11, 11);
    }

  • Simulate keystrokes with the Keys action (for more information, see the Simulating Keystrokes topic). You can navigate to the DateTimePicker control by simulating pressing the Right and Left keys and set the hours, minutes, seconds and time period by simulating pressing the Up, Down, numeric or letter keys.

    The following example demonstrates how you can set time in the DateTimePicker control that is displayed on the fourth page of Windows Scheduled Task Wizard (this page is shown for the tasks that are supposed to be executed only once) using the Keys action:

    JavaScript, JScript

    function Main()
    {
      var DateTimePicker;

      // Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1);

      // Set the insertion point
      DateTimePicker.Click(12,11);
        
      // Navigate to the control and set the time
      DateTimePicker.Keys ("1[Right][Up][Up][Right]AM");
    }

    Python

    def Main():
    
      # Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1)
    
      # Set the insertion point 
      DateTimePicker.Click(12,11)
        
      # Navigate to the control and set the time
      DateTimePicker.Keys ("1[Right][Up][Up][Right]AM")

    VBScript

    Sub Main
      Dim DateTimePicker

      ' Obtain the DateTimePicker control
      Set DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 1)

      ' Set the insertion point
      Call DateTimePicker.Click(12, 11)
       
      ' Navigate to the control and set the time
      DateTimePicker.Keys "1[Right][Up][Up][Right]AM"
    End Sub

    DelphiScript

    procedure Main;
    var DateTimePicker;
    begin
      // Obtain the DateTimePicker control
      DateTimePicker := Sys.Process('Explorer').Window('#32770', 'Scheduled Task Wizard', 1).Window('#32770', '', 1).Window('SysDateTimePick32', '', 1);

      // Set the insertion point
      DateTimePicker.Click(12,11);
       
      // Navigate to the control and set the time
      DateTimePicker.Keys ('1[Right][Up][Up][Right]AM');
    end;

    C++Script, C#Script

    function Main()
    {
      var DateTimePicker;

      // Obtain the DateTimePicker control
      DateTimePicker = Sys["Process"]("Explorer")["Window"]("#32770", "Scheduled Task Wizard", 1)["Window"]("#32770", "", 1)["Window"]("SysDateTimePick32", "", 1);

      // Set the insertion point
      DateTimePicker["Click"](12,11);
       
      // Navigate to the control and set the time
      DateTimePicker["Keys"] ("1[Right][Up][Up][Right]AM")
    }

See Also

Working With DateTimePicker Controls in Desktop Windows Applications
wTime Property (DateTimePicker Controls)
wIsDateFormat Property (DateTimePicker Controls)
wChecked Property (DateTimePicker Controls)
Simulating Keystrokes
aqDateTime Object
SetTimeElements Method

Highlight search results