Service Test 11.20 – How to Automatically Increment a Date

Automation Guild Online Conference Top ad

Question of the Week at www.joecolantonio.com

Today's Question of the Week comes from my blog friend Irfan who asks “Is there any way to put auto generated date field? For example, I want the code to retrieve current system date and then add 20 days for check date. I just want to know how to add this kind of code.

My Answer:

First – thanks for the question, Irfan, and I'm glad you like my site! There are two ways I can think of that will get the date functionality you need:

  • The first method uses custom code.
  • The second method can be done using Service Test 11.20 built in Date/Time activities.

How to Increment a Date using Custom Code

  1. In Service Test, drag a custom code activity to the main canvas area.
  2. Under the Custom Code properties section, select Events, and for the ExecuteEvent select “create a default handler.”


  1. Under the CodeActivity_OnexecuteEvent add the following lines of code:

    DateTime today = DateTime.Now;

    DateTime futureDate = today.AddDays(20);

    MessageBox.Show(futureDate.ToString(mdy));

  2. Run the test. A message box should appear with the correct future date.

How to Increment a Date using Service Test's built-in Date/Time activities

  1. In Service Test, click on the Date/Time folder under the Toolbox.
  2. Drag an Increment Date/Time to the main canvas.
  3. Drag a Form Date/Time to the main canvas.
  4. Click on the Increment Date/Time properties and click on the Original Date/Time “link to data source.”
  5. In the Select Link Source dialogue box, click on Test variables and select the CurrentDate system variable.


  1. Change the Units property to Days.
  2. Change the Amount to 20.


  1. Click on the Format Date/Time and set the following properties:
  • Input Date/Time = link to the Increment Date/Time ‘Result.'


  • Format = mm/dd/yyyy
  1. Run the test. The future date should appear in the output section:


Want your question answered in a post?

Would you like your question to be answered as a post on joecolantonio.com? Well, it's easy. All you have to do is e-mail me your question, or add a comment to an existing post. At the end of each week I'll select the best question and answer it in a post. Cool!

Click here to add a comment

Leave a comment: