InBuilt Date Functions - VBSCript In QTP

How to : Use Inbuilt Date functions in QTP via VBScript effectively .

The common date related functions that we use very often during QTP automation are classified as under, one by one we will discuss each of them in detail.

Date
DateAdd
DateDiff
CDate
DatePart
DateSerial
DateValue
Year
FormatDateTime
Day
IsDate
Weekday


Let us explore them individually with example below.

Msgbox("The current system date is: " & Date)
Msgbox(DateAdd("yyyy",1,"31-Jan-10") )
Msgbox(DateAdd("q",1,"31-Jan-10") )
Msgbox(DateAdd("m",1,"31-Jan-10") )
Msgbox(DateAdd("y",1,"31-Jan-10") )
Msgbox(DateAdd("d",1,"31-Jan-10") )
Msgbox(DateAdd("w",1,"31-Jan-10") )
Msgbox(DateAdd("ww",1,"31-Jan-10") )
Msgbox(DateAdd("h",1,"31-Jan-10 08:50:00") )
Msgbox(DateAdd("n",1,"31-Jan-10 08:50:00") )
Msgbox(DateAdd("s",1,"31-Jan-10 08:50:00") )

fromDate="31-Jan-09 00:00:00"
toDate="31-Jan-10 23:59:00"
Msgbox(DateDiff("yyyy",fromDate,toDate) )
Msgbox(DateDiff("q",fromD,toDate) )
Msgbox(DateDiff("m",fromDate,toDate) )
Msgbox(DateDiff("y",fromDate,toDate) )
Msgbox(DateDiff("d",fromDate,toDate) )
Msgbox(DateDiff("w",fromDate,toDate) )
Msgbox(DateDiff("ww",fromDate,toDate) )
Msgbox(DateDiff("h",fromDate,toDate) )
Msgbox(DateDiff("n",fromDate,toDate) )
Msgbox(DateDiff("s",fromDate,toDate) )



d=CDate("2010-02-16")
Msgbox(DatePart("m",d))
Msgbox(DatePart("m",Now()))
Msgbox(DatePart("h",Now())


Msgbox(DateSerial(2010,2,3))
Msgbox(DateSerial(2010,2,3-10))

Msgbox(DateValue("31-Jan-10"))
Msgbox(DateValue("31-Jan"))

Msgbox(Year("2010-02-16"))
d=CDate("2010-02-16 13:45")
Msgbox(FormatDateTime(d))
Msgbox(FormatDateTime(d,1))
Msgbox(FormatDateTime(d,2) )
Msgbox(FormatDateTime(d,3) )
Msgbox(FormatDateTime(d,4))

Msgbox(Day("2010-02-16"))
Msgbox(IsDate("April 22, 1947"))
Msgbox(IsDate(#01/31/10#))

Msgbox(IsDate("#01/31/10#"))
Msgbox(IsDate("52/17/2010"))
Msgbox(IsDate("Hello World!"))


Msgbox(Weekday("2010-02-16",1))
Msgbox(Weekday("2010-02-16",2) )
Msgbox(Weekday("2010-02-16",3) )
Msgbox(Weekday("2010-02-16",4))
Msgbox(Weekday("2010-02-16",5) )
Msgbox(Weekday("2010-02-16",6) )

For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP

0 comments:

Post a Comment