Results 1 to 15 of 15

Thread: How to convert system date to specified date in QTP 9.2?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Nov 2005
    Answers
    10

    How to convert system date to specified date in QTP 9.2?

    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,


  2. #2

    Re: How to convert system date to specified date in QTP 9.2?

    To what format do you want your dates converted?


  3. #3
    Junior Member
    Join Date
    Nov 2005
    Answers
    10

    Re: How to convert system date to specified date in QTP 9.2?

    Quote Originally Posted by Anshoo_Arora View Post
    To what format do you want your dates converted?
    Hi,

    the system date displayed in m-d/yyyy..i want to convert it into mm/dd/yy..

    Please let me know how this can be done?

    Thanks,
    Mythreyi


  4. #4

    Re: How to convert system date to specified date in QTP 9.2?

    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


  5. #5

    Re: How to convert system date to specified date in QTP 9.2?

    Usage:

    MsgBox dateManipulate("4-5/2007")
    MsgBox dateManipulate("12-12/2007")
    MsgBox dateManipulate("12-1/2007")
    MsgBox dateManipulate("1-10/2007")


  6. #6
    Junior Member
    Join Date
    May 2008
    Answers
    11

    Re: How to convert system date to specified date in QTP 9.2?

    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


  7. #7
    Junior Member
    Join Date
    Nov 2005
    Answers
    10

    Re: How to convert system date to specified date in QTP 9.2?

    Hi,

    Thanks for the information..but unfortunately i could not test this as my QTP demo version is expired...;-(

    Thanks

    Quote Originally Posted by shv_shanmu24 View Post
    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



  8. #8
    Expert Member
    Join Date
    Jan 2007
    Answers
    211

    Re: How to convert system date to specified date in QTP 9.2?

    u can simply run the code in a vbscript file.

    Regards,
    Nawab


  9. #9

    Re: How to convert system date to specified date in QTP 9.2?

    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.


  10. #10
    Junior Member
    Join Date
    May 2008
    Answers
    11

    Re: How to convert system date to specified date in QTP 9.2?

    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.


  11. #11

    Re: How to convert system date to specified date in QTP 9.2?

    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.


  12. #12
    Junior Member
    Join Date
    Feb 2007
    Answers
    2

    Re: How to convert system date to specified date in QTP 9.2?

    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


  13. #13
    Junior Member
    Join Date
    Feb 2007
    Answers
    2

    Re: How to convert system date to specified date in QTP 9.2?

    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.


  14. #14
    Expert Member
    Join Date
    Oct 2007
    Answers
    126

    Re: How to convert system date to specified date in QTP 9.2?

    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


  15. #15
    Junior Member
    Join Date
    Mar 2011
    Answers
    1

    Re: How to convert system date to specified date in QTP 9.2?

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact