Thread: Imprecise Dates
View Single Post
Old 01-02-2021, 10:36 AM   #4
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,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I would consider adding 2 columns: one text column to enter the date and a composite column to display it.

You would enter the date using some version of a string that supplies the numbers and the desired format. Example:
Y,1984
YM,1984,12
YMD,1984,12,04
The template for the composite column would split the "list" into its component parts then reassemble them as desired. Something like:
Code:
program:
# date_string = field('#other_column')
	date_string = 'YMD,1984,12, 01';
	format = list_item(date_string, 0, ',');
	if format == 'YMD' then
		strcat(
			list_item(date_string, 1, ','), '-',
			list_item(date_string, 2, ','), '-',
			list_item(date_string, 3, ',')
		)
	elif format == 'YM'  then
		strcat(
			list_item(date_string, 1, ','), '-',
			list_item(date_string, 2, ',')
		)
	elif format == 'Y'  then
			list_item(date_string, 1, ',')
	else
			'Invalid Format'
	fi

Last edited by chaley; 01-03-2021 at 06:22 AM. Reason: Fix template
chaley is offline   Reply With Quote