Example -
Below code will verify date format in QTP. To verify the dates, you must have actual and expected dates in same format.
So you must convert the dates in a typical format like ddmmyyyy or mmddyyyy etc.
Below function will get the date in mm/dd/yyyy format.
Call Getdate("T") - will return todays date
Call Getdate("T+1") - will return tommorrow's date
Call Getdate("T-1") - Will return previous day's date.
you can calculate any future or past date with this example.
Function GetDate(byval curvalue)
If ucase(curvalue) = "T" Then
curvalue = curvalue & "+0"
End If
If instr(1,curvalue,"+") > 0 Then
arrdate = split(curvalue,"+")
retDate = dateadd("d",arrdate(1),now)
strmonth = month(cdate(retDate))
strday = day(cdate(retDate))
stryear = year(cdate(retDate))
If len(strmonth) = 1 Then
strmonth = "0" & strmonth
End If
If len(strday) = 1 Then
strday = "0" & strday
End If
Else
arrdate = split(curvalue,"-")
curDate = - cint(arrdate(1))
retDate = dateadd("d",curDate,now)
strmonth = month(cdate(retDate))
strday = day(cdate(retDate))
stryear = year(cdate(retDate))
If len(strmonth) = 1 Then
strmonth = "0" & strmonth
End If
If len(strday) = 1 Then
strday = "0" & strday
End If
End If
If Ucase(strParameter1) = "YYYY-MM-DD" Then
GetDate = stryear & "-" & strmonth & "-" & strday
Else
GetDate = strmonth & "/" & strday & "/" & stryear
End If
End Function
Please find below more questions and answers on date and time in QTP.
Below code will verify date format in QTP. To verify the dates, you must have actual and expected dates in same format.
So you must convert the dates in a typical format like ddmmyyyy or mmddyyyy etc.
Below function will get the date in mm/dd/yyyy format.
Call Getdate("T") - will return todays date
Call Getdate("T+1") - will return tommorrow's date
Call Getdate("T-1") - Will return previous day's date.
you can calculate any future or past date with this example.
Function GetDate(byval curvalue)
If ucase(curvalue) = "T" Then
curvalue = curvalue & "+0"
End If
If instr(1,curvalue,"+") > 0 Then
arrdate = split(curvalue,"+")
retDate = dateadd("d",arrdate(1),now)
strmonth = month(cdate(retDate))
strday = day(cdate(retDate))
stryear = year(cdate(retDate))
If len(strmonth) = 1 Then
strmonth = "0" & strmonth
End If
If len(strday) = 1 Then
strday = "0" & strday
End If
Else
arrdate = split(curvalue,"-")
curDate = - cint(arrdate(1))
retDate = dateadd("d",curDate,now)
strmonth = month(cdate(retDate))
strday = day(cdate(retDate))
stryear = year(cdate(retDate))
If len(strmonth) = 1 Then
strmonth = "0" & strmonth
End If
If len(strday) = 1 Then
strday = "0" & strday
End If
End If
If Ucase(strParameter1) = "YYYY-MM-DD" Then
GetDate = stryear & "-" & strmonth & "-" & strday
Else
GetDate = strmonth & "/" & strday & "/" & stryear
End If
End Function
Please find below more questions and answers on date and time in QTP.
- How to extract date part from timestamp in QTP?
- How to find the name of month of given date in QTP?
- How to extract time part from given date in QTP?
- How to extract the second part from given time stamp in QTP?
- Explain dateadd function in qtp with Example.
- How to find future date in qtp?
- How to get the system date in qtp?
- How to verify the date format in qtp?
- How to find the yesterday's date in qtp
- How to find the date difference in qtp
- How to get the current system date in qtp?
- How to get the current year in qtp?
- How to find the name of week day for given date in QTP?
- Explain now function in qtp.
- Explain the datediff function in qtp.
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs