Interview Questions   Tutorials   Discussions   Programs   Videos

# QTP - Is it possible to change the date format like MM/DD/YY into DD/MM?YY through script in QTP

558
views
asked marvit August 23, 2014 01:12 AM

Is it possible to change the date format like MM/DD/YY into DD/MM?YY through script 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.
To get date in any other format you need to modify last part of function.

Below function will get the date in mm/dd/yyyy format.
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,"+")

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))

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

flag

### Join with account you already have

Preview

Online-Classroom Classes
www.writeabc.com

1 person following this question

1 person following this tag

Question tags

qtp × 1

Asked 3 years and 5 months ago ago
Number of Views -558