Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Understanding Date time function: Using VBScript in QTP

Below are some of the useful function for working with date/time in vb script. We will use the functions and illustrate where the functions can be used.


1. Date - This returns the current date of the system.


2. Now - This returns the current Date and time of the system.So now contains time part as well as date part while date function returns only date.


3. Time - This returns the current time of the system. So in terms of relation between date , time, and now function 


Now = date + time

4. Year, Month, Day, hour, minute, second - These functions return year, month,day,hour,minute,second part for the expression.


example : day(now) or  minute(now)

Above functions discussed above are useful for timestamp , and also for generating a unique number based on the function used.


5. Timer - Timer returns the number of seconds from 12:00a.m. This function is very useful for evaluating time spent in performing an activity by taking timer at the start and end of the activity and subtracting the time between two.


6. DatePart - returns specific part of the date .Possible values or part of date , that can be extracted as shown below:

  • yyyy - Year
  • q - Quarter
  • m - Month
  • y - Day of year
  • d - Day
  • w - Weekday
  • ww - Week of year
  • h - Hour
  • n - Minute
  • s - Second
Syntax of the function is : DatePart("m",d))where d is the date as "2013-06-09" and m will return the month of the date.

7. DateDiff - Returns the difference between two dates: 

Syntax : DateDiff(interval,date1,date2). Interval can be yyyy,q,m, y,d,.... as discussed earlier.


8. DateAdd - Add specified date to the date.

Syntax : DateAdd(interval,number,date)


3 comments:

  1. Is there any function like TimeAdd in QTP??
    i need to show time after 10minutes using vbscript

    ReplyDelete
  2. Hi, you can use dateAdd and datediff to add or reduce the required time.

    DateAdd("h",1,"31-Dec-13 09:10:00")
    DateAdd("m",1,"31-Dec-13 09:10:00")
    DateAdd("s",1,"31-Dec-13 09:10:00")

    ReplyDelete
  3. how to edit time by 15 minutes? Is it possible?

    ReplyDelete