Setting DateTimePicker Date

Applies to TestComplete 14.20, last modified on September 11, 2019

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 a date in the DateTimePicker control by doing one of the following:

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

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

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

    Below is an example that demonstrates how you can select a date 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", "", 2);

      // Set the date
      DateTimePicker.wDate = "11/28/2007";
    }

    Python

    def Main():
    
      # Obtain the DateTimePicker control 
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 2)
    
      # Set the date
      DateTimePicker.wDate = "11/28/2007"

    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", "", 2)

      ' Set the date
      DateTimePicker.wDate = "11/28/2007"
    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', '', 2);

      // Set the date
      DateTimePicker.wDate := '11/28/2007';
    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", "", 2);

      // Set the date
      DateTimePicker["wDate"] = "11/28/2007";
    }

    You can do the same using the SetDateElements method of the aqDateTime object. This method returns a specific value calculated from the given year, month and day.

    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", "", 2);

      // Set the date
      DateTimePicker.wDate = aqDateTime.SetDateElements(2008, 6, 4);
    }

    Python

    def Main():
    
      # Obtain the DateTimePicker control 
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 2)
    
      # Set the date
      DateTimePicker.wDate = aqDateTime.SetDateElements(2008, 6, 4)

    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", "", 2)

      ' Set the date
      DateTimePicker.wDate = aqDateTime.SetDateElements(2008, 6, 4)
    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', '', 2);

      // Set the date
      DateTimePicker.wDate := aqDateTime.SetDateElements(2008, 6, 4);
    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", "", 2);

     // Set the date
     DateTimePicker["wDate"] = aqDateTime["SetDateElements"](2008, 6, 4);
    }

  • Use the DateTimePicker control’s popup calendar. You can display it using the DropDown action and select a date by simulating pressing the Down, Up, Left and Right keys (this can be done via the Keys action). To close the control’s popup calendar, use the CloseUp action.

    The code below demonstrates how to do this for 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 DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 2);

      // Display the control's popup calendar
      DateTimePicker.DropDown();

      // Select the date
      DateTimePicker.Keys("[Right][Down][Down]");

      // Post the selected date to the log
      Log.Message(DateTimePicker.wDate);

      // Close the control's popup calendar
      DateTimePicker.CloseUp();
    }

    Python

    def Main():
              
      # Obtain DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 2)
    
      # Display the control's popup calendar
      DateTimePicker.DropDown()
    
      # Select the date
      DateTimePicker.Keys("[Right][Down][Down]")
    
      # Post the selected date to the log
      Log.Message(DateTimePicker.wDate)
    
      # Close the control's popup calendar
      DateTimePicker.CloseUp()

    VBScript

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

      ' Display the control's popup calendar
      DateTimePicker.DropDown

      ' Select the date
      DateTimePicker.Keys "[Right][Down][Down]"

      ' Post the selected date to the log
      Log.Message(DateTimePicker.wDate)

      ' Close the control's popup calendar
      DateTimePicker.CloseUp
    End Sub

    DelphiScript

    procedure Main;
    var DateTimePicker;
    begin

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

      // Display the control's popup calendar
      DateTimePicker.DropDown;

      // Select the date
      DateTimePicker.Keys('[Right][Down][Down]');

      // Post the selected date to the log
      Log.Message(DateTimePicker.wDate);

      // Close the control's popup calendar
      DateTimePicker.CloseUp;
    end;

    C++Script, C#Script

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

      // Display the control's popup calendar
      DateTimePicker["DropDown"]();

      // Select the date
      DateTimePicker["Keys"]("[Right][Down][Down]");

      // Post the selected date to the log
      Log["Message"](DateTimePicker["wDate"]);

      // Close the control's popup calendar
      DateTimePicker["CloseUp"]();
    }

  • 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 day, month and year by simulating pressing the Up, Down or numeric keys.

    The example below demonstrates how you can set a date 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", "", 2);

      // Set the insertion point
      DateTimePicker.Click(12,11);
      
      // Navigate to the control and set a date
      DateTimePicker.Keys ("12[Right]13[Right][Up][Up]");

      // Post the selected date to the log
      Log.Message(DateTimePicker.wDate);
    }

    Python

    def Main():
    
      # Obtain the DateTimePicker control
      DateTimePicker = Sys.Process("Explorer").Window("#32770", "Scheduled Task Wizard", 1).Window("#32770", "", 1).Window("SysDateTimePick32", "", 2)
    
      # Set the insertion point 
      DateTimePicker.Click(12,11)
      
      # Navigate to the control and set a date
      DateTimePicker.Keys ("12[Right]13[Right][Up][Up]")
    
      # Post the selected date to the log
      Log.Message(DateTimePicker.wDate)

    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", "", 2)

      ' Set the insertion point
      Call DateTimePicker.Click(12, 11)
      
      ' Navigate to the control and set a date
      DateTimePicker.Keys "12[Right]13[Right][Up][Up]"

      ' Post the selected date to the log
      Log.Message(DateTimePicker.wDate)
    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', '', 2);

      // Set the insertion point
       DateTimePicker.Click(12,11);
       
      // Navigate to the control and set a date
      DateTimePicker.Keys ('12[Right]13[Right][Up][Up]');

      // Post the selected date to the log
      Log.Message(DateTimePicker.wDate);
    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", "", 2);

      // Set the insertion point
      DateTimePicker["Click"](12,11);
       
      // Navigate to the control and set a date
      DateTimePicker["Keys"]("12[Right]13[Right][Up][Up]");

      // Post the selected date to the log
      Log["Message"](DateTimePicker["wDate"]);
    }

See Also

Working With DateTimePicker Controls
wDate Property (DateTimePicker Controls)
wIsDateFormat Property (DateTimePicker Controls)
wChecked Property (DateTimePicker Controls)
DropDown Action (DateTimePicker Controls)
CloseUp Action (DateTimePicker Controls)
Simulating Keystrokes
aqDateTime Object
aqDateTime.SetDateElements Method

Highlight search results