View Single Post
Old 12-27-2012, 08:06 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,461
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I meant to answer this sometime back, but got busy.

The following general program mode template does what I think you want.
Code:
program:
	date = field('#original_date');
# compute the components
	year = subitems(date, 0, 1);
	month = re(subitems(date, 1, 2), '^\D*$',  '00');
	day = ifempty(subitems(date, 2, 3), '00');
# compute the return value
	strcat(year, '--', month, '--', day)
The trickiest part is the call to re. The pattern matches if the source contains only non-numeric characters, replacing them with '00' otherwise leaving them alone.
chaley is offline   Reply With Quote