Friday

QTP - Get future date/ working date

From SQAfornm:


a=GetTDate(6)

msgbox a

Public Function GetTDate(iDays)
Dim dDate, iDir, d, i
dDate = Date
If iDays > -1 Then iDir = 1 else iDir = -1 end if

For i = 1 to Abs(iDays)
d = DateAdd("d", iDir, dDate)
While DatePart("w", d) = 7 or DatePart("w", d) = 1
d = DateAdd("d", iDir, d)
Wend
dDate = d
Next
GetTDate = dDate
End Function


You can use the DateAdd function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now. To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").

The DateAdd function won't return an invalid date. The following example adds one month to January 31:

NewDate = DateAdd("m", 1, "31-Jan-95")
In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.

If the calculated date would precede the year 100, an error occurs.

If number isn't a Long value, it is rounded to the nearest whole number before being evaluated
DatePart(interval, date[, firstdayofweek[, firstweekofyear]])

No comments:

Post a Comment