Hi All,
I am trying to convert system date into a specified format...(like mm/dd/yy) in QTP 9.2...
Can anyone tell me how this could be done?
Thanks in Advance,
Hi All,
I am trying to convert system date into a specified format...(like mm/dd/yy) in QTP 9.2...
Can anyone tell me how this could be done?
Thanks in Advance,
To what format do you want your dates converted?
Public Function dateManipulate(sDate)
If Len(sDate) > 10 Then
Reporter.ReportEvent micWarning, "Error! Bad Input", "Bad Input. Actual: " & sDate & ". Expected: m-d/yyyy"
End If
locDelimOne = InStr(1, sDate, "-")
locDelimTwo = InStr(1, sDate, "/")
If locDelimOne = 2 Then
sMonth = Left(sDate, 1)
sMonth = "0" & sMonth
ElseIf locDelimOne = 3 Then
sMonth = Left(sDate, 2)
Else
Reporter.ReportEvent micWarning, "Error! Bad Input", "Bad Input. Actual: " & sDate & ". Expected: m-d/yyyy"
End If
sDay = Mid(sDate, locDelimOne + 1, locDelimTwo - locDelimOne - 1)
If Len(sDay) = 1 Then
sDay = "0" & sDay
End If
sLen = Len(sDate) - locDelimTwo
sYear = Mid(sDate, locDelimTwo + 3, sLen)
iDate = sMonth & "/" & sDay & "/" & sYear
dateManipulate = iDate
End Function
Usage:
MsgBox dateManipulate("4-5/2007")
MsgBox dateManipulate("12-12/2007")
MsgBox dateManipulate("12-1/2007")
MsgBox dateManipulate("1-10/2007")
Hi,
Please try on the following Code which will help to convert the system date to specified format(mm/dd/yy)
Code:
SystemDate = Date
Date1 = Datepart("d",SystemDate)
month1 = Datepart("m",SystemDate)
year1 = Datepart("yyyy",SystemDate)
If len(Date1) = 1 then
Date1 = "0" & Date1
Else
Date1 = Date1
End If
If len(month1) = 1 then
month1 = "0" & month1
Else
month1 = month1
End If
year1= Right(year1,2)
Converted_date = month1 & "/" & Date1 & "/" & year1
u can simply run the code in a vbscript file.
Regards,
Nawab
shv_shanmu24, I would only like to add that your code is not going to convert the date from the format mythreyi has posted in the original post. It is only going to work for System Dates.
Hi Anoosh,
i read the thread name "How to convert the system date into specified format?" alone and i didn't have a look into the conversation that went between you and mythreyi. So, i provided that code.
Hi Mytheri,
you can use the code suggested by Anoosh.
Sorry for providing you the code which does not meet your exact expectation.
Well, that's alright. There is no need to apologize to anyone.
My only intent was to point this out for mytheryi and other readers who visit this board.
I need to do the same. I want to change the format of the date. I was trying to use shanmu's code, i am getting an error. Invalid procedure call or argument: 'Datepart'
at Date1 = Datepart("dd",SystemDate)
Can some one please advice
I had to use Date1 = Datepart("d",SystemDate) instead of Date1 = Datepart("dd",SystemDate)
I got this resolved
But I recorded a gui application where I enter that days date in it. So when i run the script next day it takes y'days date but i want to use the present days date. How can I do that
Can you advice.
Hi lvr,
before executing the yesterdays script just mention a statement for system date.
for ex:
Dim MyDate
MyDate = Date
in VB script "Date" is for todays date.
Cheers,
Bhaskar Kumar
this is the most simplest way, you can do for user defined date formate and date addition and subtration
msgbox Day(Date)&"/"&Month(Date)&"/"&Year(Date)
msgbox Day(Date+1)&"/"&Month(Date+1)&"/"&Year(Date+1)
msgbox Day(Date-1)&"/"&Month(Date-1)&"/"&Year(Date-1)
Regards,
Venkat