Forum Discussion

nolandsmith's avatar
nolandsmith
New Contributor
2 years ago

Regex with Dates

Is it possible to change the date format with RegEx?

 

The standard format with dates is: YYYY-MM-DD

 

However, I need all dates in MM/DD/YYY

 

Is it possible to place YYYY on the end, and replace the "-" with "/" ?

 

Please let me know if anyone has been able to solve this before!

3 Replies

  • You could use a property with type: string and a pattern: <regex> tag to enforce your desired date format. Pattern can be crafted to make sure year starts with a 1 or 2, month is 01 to 12 and days are correct for the designated month. Don’t forget leap years !

     

    lots of good examples here: https://www.google.com/search?q=date+regex+mm%2Fdd%2Fyyyy&rlz=1C9BKJA_enCH591CH591&oq=date+regex&aqs=chrome.1.69i57j0i512l4j69i60.7047j0j7&hl=en-GB&sourceid=chrome-mobile&ie=UTF-8

     

    • nolandsmith's avatar
      nolandsmith
      New Contributor

      Thanks for much for the quick response!

      I might be misunderstanding the point of the Pattern property. No matter what I put in the regex expression, the output always come back in the same format "YYY-MM-DD"

       

      Can we use Regex to change the actual output value format? (apologies I'm new to Regex)

       

       

      • mhiggins's avatar
        mhiggins
        Staff
        Ah, I wasn’t clear. Name the property as you see fit. But make it type: string with just a pattern tag, no format tag. Add default, example tags optionally.

        --
        Micheál Higgins
        Senior Solutions Architect
        SmartBear Software

        Sent from my iPad


        We hope you found this email of interest; however, click here if you wish to unsubscribe<> or manage your email preferences. Privacy Policy.<>

        Disclaimer

        The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.