This post is a continuation of QTP code snippets. You can check QTP Code Snippets – Part 1 here.

  • Formatting the date and time value

FormatDateTime() function returns an expression formatted as date and time. The function has Date part and NamedFormat part. Example: If the application returns the time stamp and we need only date and not time then we can use the function as shown:

createdTime = FormatDateTime(“06/05/2009 10:15 AM”,2)




  • Comparing difference in date

DateDiff() function returns the number of intervals between two dates

DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])

Example: We are going to compare the present date with the date passed through FormatDateTime() function to check if it Today’s date.

createdTime = FormatDateTime(“06/05/2009 10:15 AM”,2)

If DateDiff(“d”,createdTime,date) = 0 Then

Msgbox(“Its Present Date”)


Msgbox(“Its not Todays date, its another day”)

End If

  • Passing parameter from one action to another

Before passing a parameter from one action to another input parameter needs to be created for the action which is going to accept a value as input from another action. Lets take Action 2 is going to get an value from Action 1 as a parameter, then first create an input parameter for the Action 2. This can be done by right clicking on the Action 2 Action Properties à Clicking on Properties Tab and Clicking the “+” sign to create a parameter. Now lets say we are going to pass an integer variable from Action 1 to Action 2, hence I can create a number parameter in the input parameter of Action2. The code snippet will look like the following:


a = 10

b= 20

c= a+b

RunAction “Action2″, oneIteration,c



d = 10

result = Parameter(“c”)

e = result+d


Note: Set c as input parameter in Action2

More code snippets in the next post.