1

I have a keyboard macro tool (keyboard maestro) that returns current date in %NumberDate% variable; it contains a string "3/31/15" for March 31, 2015.

The tool supports regular expression, so using the regular expression, I need to transform this value into formatted string of [yyyy/MM/dd] format; in this example [2015/03/31].

The expression that I used to extract the information is (\d+)/(\d+)/(\d+), however, [20$3/$1/$2] makes [2015/3/31] not [2015/03/31]. Is there any way to check if $1 or $2 is one digit to insert 0 automatically?

enter image description here

prosseek
  • 182,215
  • 215
  • 566
  • 871

2 Answers2

1

enter image description here

I could use ICUDateTimeFor to get and replace the date format.

%ICUDateTimeFor%NOW()+20%[yyyy/MM/dd]%
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • I never knew about `ICUDateTimeFor`, and think your solution is better than what I had come up with. Mine involved adding `Execute Shell Script` between tasks 1 and 2 in your question and using sed: `echo $KMVAR_date | sed 's/^[0-9]\//0&/' | sed 's/\.*\/\([0-9]\)\/(./\/0\1\//'` – l'L'l Apr 03 '15 at 18:58
0

You can just use the standard ICUDateTime, you don't need the ICUDateTimeFor.

enter image description here

JMichaelTX
  • 1,659
  • 14
  • 19