Page 1 of 1

date format help

Posted: Wed Jul 18, 2012 2:05 pm
by srive99
Hello All,

I have a date coming to my application and within the application I need to convert date format using regex. Could some one help me.

my input date could be any of following...
this is just an example date

12/12/12
1/12/12
12/1/12
12/12/2012
1/12/2012
12/1/2012

and my desired output should be 12/12/2012 (dd/mm/yy).

For example, if input date is (18/7/12) I will need to convert that to 18/07/2012.

Thanks

Posted: Wed Jul 18, 2012 5:58 pm
by ben_josephs
Are dates the only things containing digits in your text?

If so, try the following:

0. Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
1. Inset a leading zero in front of single digits:
Find what: \<([0-9])\>
Replace with: 0\1

[X] Regular expression

Replace All
2. Insert 20 in front of 2-digit years:
Find what: \<([0-9][0-9]/[0-9][0-9])/([0-9][0-9])\>
Replace with: \1/20\2

[X] Regular expression

Replace All

Posted: Wed Jul 18, 2012 7:48 pm
by kengrubb
ben_josephs,

You rock! I can count on learning more about RE and TP from you.