SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 3 of 3
  1. #1
    Advanced Member
    Join Date
    Jan 2004
    Location
    UK
    Posts
    817
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Regular expressions for Date

    Hi,
    Try this and see if it helps. Found this on another forum:

    ' 1 for mm/dd/yyyy, m/dd/yyyy, mm/d/yyyy or m/d/yyyy to yyyy-mm-dd
    '
    ' 2 for mm/dd/yy, m/dd/yy, mm/d/yy or m/d/yy to yyyy-mm-dd
    '
    ' 3 for yyyy-mm-dd to mm/dd/yyyy
    '
    ' 4 for yyyy-mm-dd to mm/dd/yy

    Public Function ReformatDate(inDate, format)

    Select Case format
    Case 1
    Select Case Len(inDate)
    Case 8
    ReformatDate = Mid(inDate, 5, 4) & "-0" & Mid(inDate, 1, 1) & "-0" & Mid(inDate, 3, 1)
    Case 9
    If InStr(inDate, "/") = 2 Then
    ReformatDate = Mid(inDate, 6, 4) & "-0" & Mid(inDate, 1, 1) & "-" & Mid(inDate, 3, 2)
    Else
    ReformatDate = Mid(inDate, 6, 4) & "-" & Mid(inDate, 1, 2) & "-0" & Mid(inDate, 4, 1)
    End If
    Case 10
    ReformatDate = Mid(inDate, 7, 4) & "-" & Mid(inDate, 1, 2) & "-" & Mid(inDate, 4, 2)
    End Select
    Case 2
    Select Case Len(inDate)
    Case 6
    ReformatDate = "20" & Mid(inDate, 5, 2) & "-0" & Mid(indate, 1, 1) & "-0" & Mid(inDate,3 ,1)
    Case 7
    If InStr(inDate, "/") = 2 Then
    ReformatDate = "20" & Mid(inDate, 6, 2) & "-0" & Mid(inDate, 1, 1) & "-" & Mid(inDate, 3, 2)
    Else
    ReformatDate = "20" & Mid(inDate, 6, 2) & "-" & Mid(inDate, 1, 2) & "-0" & Mid(inDate, 4, 1)
    End If
    Case 8
    ReformatDate = "20" & Mid(inDate, 7, 2) & "-" & Mid(inDate, 1, 2) & "-" & Mid(inDate, 4, 2)
    End Select
    Case 3
    ReformatDate = mid(inDate, 6, 2) & "/" & Mid(inDate, 9, 2) & "/" & mid(inDate, 1, 4)
    Case 4
    ReformatDate = mid(inDate, 6, 2) & "/" & Mid(inDate, 9, 2) & "/" & mid(inDate, 3, 2)
    End Select

    End Function
    I like what i know and I know what i like

  2. #2
    Senior Member
    Join Date
    Jan 2005
    Location
    VA
    Posts
    237
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Regular expressions for Date

    I try to check whether a date has a valid format of MM/DD/200Y, and I followed EXACTLY the instruction in Lesson 7 (Using Regular Expressions) of the QTP Tutorial.

    I entered [0-1][0-9]/[0-3][0-9]/200[0-9] in the Value box and did as direction, but the corresponding script showed

    Browser("Welcome to MSN.com").Page("United States").Check CheckPoint("[0-1][0-9]/[0-3][0-9_4")

    You can image that I ran into error on that line. Even though I tried several times, and/or manually change the script as CheckPoint("[0-1][0-9]/[0-3][0-9]/200[0-9]"). The error remains.

    Any thoughts? Thanks!
    Regards!

  3. #3
    Senior Member
    Join Date
    Jan 2005
    Location
    VA
    Posts
    237
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Regular expressions for Date

    Maxj,

    Great thanks for the ReformatDate. It suits my needs for now.

    But, not for my curiosity [img]images/icons/smile.gif[/img] ... part of my original question remains:

    Why does QTP not generate the correct script even though I followed EXACTLY the instruction in Lesson 7 of the QTP Tutorial? Maybe I shall post this question to Mercurry Tech Support.

    Anyway, great thanks again.

    --Chin
    Regards!

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:15 AM.

Copyright BetaSoft Inc.