Different types of Date Functions in QTP?

Date Functions in QTP

QTP default functions and Vb Script functions are used to define the different date formats in QTP, Such are-

How to Get Current Date value using QTP

Dim CurrentDate

CurrentDate =Date

Msgbox CurrentDate


Date Functions in QTP-Msgbox

After Executing the above code, system will show the current date in month/date/year(mm/dd/yy) format.

How to covert string into Date in QTP



Dim StringtoDate

StringtoDate =”1/12/13”   -String Date Format

VarDate =Cdate(StringtoDate) –Cdate Coverts String into a Date

Msgbox VarDate


Date Functions in QTP-Keyword View

Execute the above code and will get the defined string as a Date Output

Same can define for Time string as well


Timestring =”4:05:10 PM”


Msgbox VarTime

How to define Month Function in QTP

Dim Datemonth

Datemonth =Month(now)

Msgbox Datemonth


“1”       ‘1 represents January, 2 –Feb-…..               12 represents December’

Date and Time Constants:

vbSunday 1 Sunday
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
vbUseSystemDayOfWeek 0 Use the day of the week specified in your system settings for the first day of the week.


DateAdd Function in QTP

DateAdd is used to specify the intervals, interval time and Date


DateAdd (Interval,number,date)


Intervals are either Month, Year, Quarter, Day of the Year, Day, WeakDay, Hour, Minute or second

Find the below list for more Details about intervals

Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second


Number argument –Either It’s a positive or negative number, Positive means from the date it calculates Interval(future), Negative means interval calculates on past.

Date argument

Date is the string format based on the interval this will change it, see the below example

Ex. DateAdd(“m”, “2”,”15-07-2013”)

Output is   15-09-2013

Ex. DateAdd(“m”,”-2”,15-07-2013”)

Output is  15-05-2013

Leave a Reply

Your email address will not be published. Required fields are marked *