Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Date Format change
#1
Solved: 10 Years, 8 Months, 4 Weeks ago
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.)
Reply
#2
Solved: 10 Years, 8 Months, 4 Weeks ago
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)
Reply
#3
Solved: 10 Years, 8 Months, 4 Weeks ago
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"?
Reply
#4
Solved: 10 Years, 8 Months, 4 Weeks ago
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.
Reply
#5
Solved: 10 Years, 8 Months, 4 Weeks ago
Hi,

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

Regards,
Sankalp
Reply
#6
Solved: 10 Years, 8 Months, 4 Weeks ago
Thx sshukla12

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

I'll look it up.

cheers

L
Reply
#7
Solved: 10 Years, 8 Months, 4 Weeks ago
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
Reply
#8
Solved: 10 Years, 8 Months, 4 Weeks ago
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.
Reply
#9
Solved: 10 Years, 8 Months, 4 Weeks ago
Saajo87,

Thx, this works awsome! thx

Lor
Reply
#10
Solved: 10 Years, 8 Months, 4 Weeks ago
You could just use Replace:

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do you Change Run mode mid script? Caleytown 6 6,519 03-25-2021, 08:27 AM
Last Post: RB26578
  [UFT] Change property of object (WpfButton) robertosalemi 2 2,485 11-22-2016, 12:43 PM
Last Post: Ankur
  Dynamic change of name for Webtables prakashreddy 1 2,270 10-25-2014, 09:53 PM
Last Post: supputuri
  How can I change my test folders, globally? atester 0 1,880 10-03-2014, 04:37 PM
Last Post: atester
  QTP11.0 - Date format is changed as text while executing the QTP script. Automation Tester 1 3,904 05-30-2014, 01:25 PM
Last Post: Tarik Sheth

Forum Jump:


Users browsing this thread: 1 Guest(s)