Ask a Question

Regex with Dates

nolandsmith
New Contributor

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 3
mhiggins
Staff

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...

 

——-
Micheál Higgins
Senior Solutions Architect
m: micheal.higgins@smartbear.com

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)

 

nolandsmith_0-1664631819532.png

 

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.
——-
Micheál Higgins
Senior Solutions Architect
m: micheal.higgins@smartbear.com

cancel
Showing results for 
Search instead for 
Did you mean: