* Sortable dates in template titles

Questions about Generic and Templated Sources within FH and their associated Citations and Repositories
Post Reply
avatar
Gary_G
Megastar
Posts: 963
Joined: 24 Mar 2023 19:05
Family Historian: V7

Sortable dates in template titles

Post by Gary_G »

I typically use the following for sortable dates in templates.

Code: Select all

<{Date:YEAR}{=TextIf(%SOUR.~DT-DATE:MONTH_NUMBER% <= 9,"-0","-")}{%SOUR.~DT-DATE:MONTH_NUMBER%}{=TextIf(%SOUR.~DT-DATE:DAY% <= 9,"-0","-")}{%SOUR.~DT-DATE:DAY%}>
Unfortunately; in some situations, this does not give the expected output of YYYY-MM-DD (as indicated).
eg.
5 Apr 1891 ==> 1891-04-05 [correct]
Apr 1891 ==> 1891-04-0 [incorrect]
1891 ==> 1891-0-0 [incorrect]
[empty] ==> -- [incorrect]

As FH7 does some validation of the {Date} field, erroneous combinations are typically precluded.

In situations in which the day, month or year is not specified, one would expect the position to be filled by zeroes.
eg.
5 Apr 1891 ==> 1891-04-05 [correct]
Apr 1891 ==> 1891-04-00 [correct]
1891. ==> 1891-00-00 [correct]
[empty] ==> 0000-00-00 [correct]

I've tried various ways to get this code to yield the correct results, but have not had any luck.
Can someone suggest the needed changes?
Gary Gauthier
Hunting History in the Wild!
User avatar
Jane
Site Admin
Posts: 8543
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: Sortable dates in template titles

Post by Jane »

May be something like

Code: Select all

{=RightText(CombineText("0000",%INDI.BIRT.DATE:YEAR%,,),4)}-
{=RightText(CombineText("00",%INDI.BIRT.DATE:MONTH_NUMBER%,,),2)}-
{=RightText(CombineText("00",%INDI.BIRT.DATE:DAY%,,),2)}
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
avatar
Gary_G
Megastar
Posts: 963
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Sortable dates in template titles

Post by Gary_G »

Thank you, Jane.

With the tiny adjustments to use this approach in my Source Title format based on a templated date-type field, the following works well.
Never thought to try "CombineText".

Code: Select all

<{=RightText(CombineText("0000",%SOUR.~DT-DATE:YEAR%,,),4)}-{=RightText(CombineText("00",%SOUR.~DT-DATE:MONTH_NUMBER%,,),2)}-{=RightText(CombineText("00",%SOUR.~DT-DATE:DAY%,,),2)}>
Gary Gauthier
Hunting History in the Wild!
Post Reply