Micro Focus QTP (UFT) Forums
Date Format change - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Date Format change (/Thread-Date-Format-change)



Date Format change - mv8167 - 02-28-2012

I am trying to change the DateRequested from 2/27/2012 to 02-27-2012

my code is as such:

Code:
DateRequested = FormatDateTime(Date, 2)
Call DateManipulate(DateRequested)  'Insure date is MM/DD/YYYY format
year = Right(MM/DD/YYYY, 4)
month = left(MM/DD/YYYY, 2)
day = left(right(MM/DD/YYYY, 7), 2)
DateRequested = month & "-" & day & "-" & year

Public Function DateManipulate(eDate)

'Insure date is MM/DD/YYYY format
    Set MyDate = DotNetFactory.CreateInstance("System.DateTime")
    Set oDate = MyDate.Parse(eDate)
    DateManipulate = oDate.ToString("MM/dd/yyyy")
    eDate = DateManipulate
    'msgbox DateManipulate
    Set MyDate = Nothing

End Function


i am getting a Run Error: Overflow

What must i change? My date is returned as "02/27/2012"

(I found this code on the web and updated it with my values.)


RE: Date Format change - inborntester - 02-28-2012

Right function first argument should be string type.

Can you try like.
Code:
stryear = Right("02/27/2012", 4)
Don't use year as variable, its a keyword.

moreover you can try the simply way by using month,day,year functions.
Code:
DateRequested="02/27/2012"
DateRequested = month(DateRequested) & "-" & day(DateRequested) & "-" & year(DateRequested)
msgbox(DateRequested)



RE: Date Format change - mv8167 - 02-28-2012

Thx again Inborntester
With:
DateRequested="02/27/2012"

#1, Using:
Code:
DateRequested = month(DateRequested) & "-" & day(DateRequested) & "-" & year(DateRequested)
I get:
"2-28-2012"
#2, Using:
stryear = right(DateRequested, 4)
Code:
strmonth = left(DateRequested, 2)
strday = left(right(DateRequested, 7), 2)
DateRequested = strmonth & "-" & strday & "-" & stryear
I get:
"02-28-2012"

Can #1 also show as "02-28-2012"?


RE: Date Format change - inborntester - 02-29-2012

Can #1 also show as "02-28-2012"? - think can not at direct, but from workaround we can.
better go ahead #2 if you need 0.


RE: Date Format change - sshukla12 - 03-02-2012

Hi,

U can use Dot net factory..it will make ur life easier.

Regards,
Sankalp


RE: Date Format change - mv8167 - 03-02-2012

Thx sshukla12

Great idea. Ok, now what is Dot Net Factory. lol

I'll look it up.

cheers

L



RE: Date Format change - sshukla12 - 03-05-2012

Hi,
Like the interface u have in .net ,.net factory will provide u the same interface and u can use this to retive the date in the desired format.
Go to QTP help u will find all the details.
In any confusion let me know.

Regards,
Sankalp


RE: Date Format change - Saajo87 - 03-05-2012

Hi Lorena,

Try this..........

Code:
Dim sDate,sArr
sArr = Split(Date,"/")
sDate = sArr(0) + "-"+sArr(1)+"-"+sArr(2)

msgbox sDate

Output : 02-27-2012

~~Cheers,
Sachin.


RE: Date Format change - mv8167 - 03-05-2012

Saajo87,

Thx, this works awsome! thx

Lor


RE: Date Format change - SteveS - 03-05-2012

You could just use Replace:

NewDate = Replace(date,"/","-")