Page 1 of 1
Source Template Definition
Posted: 29 Mar 2023 14:05
by Gary_G
"tatewise" regarding
Source Template Definition and Generic Type (21739):
I am also addressing a similar issue. I am trying to construct a "Record Title Format" containing a date string. My source template contains a field called "DATE", defined as a "Date" type, and I'd like to cast it in the the format "YYYY-MM-DD".
I don't see that there is a simple function to do this, so I assume that I have to write an expression for this.
Is there somewhere I can find out what sub-structure elements are available for a source template field like the "Date" field and similar? You referred to one, when you mentioned "%SOUR.~DT-YEAR:YEAR%".
Re: Source Template Definition and Generic Type
Posted: 29 Mar 2023 15:39
by tatewise
Gary, there are two options in that case but both use the FH
Help > Generic Topics > Date Formats which define qualifiers for Date fields such as YEAR (as earlier), MONTH_NUMBER, DAY, and ABBREV3 plus others.
1) Use ABBREV3 formatting.
i.e.
{%SOUR.~DT-DATE:ABBREV3%}
That will display the current
Preferred Short Date Format which is defined in the
Tools > Preferences > General tab.
One of its options is
yyyy-mm-dd which is exactly what you want.
Just beware that it may affect Date display formats elsewhere and if you change the option it will change your Source Record Title rendering.
2) Use YEAR MONTH_NUMBER DAY formatting.
This requires all three qualifiers to be combined into a single display format with hyphen separators.
e.g.
{%SOUR.~DT-DATE:YEAR%}-{%SOUR.~DT-DATE:MONTH_NUMBER%}-{%SOUR.~DT-DATE:DAY%}
This will always display the
yyyy-mm-dd format regardless of the
Preferred Short Date Format setting.
The only caveat for both methods is that single-digit months and days do NOT display a leading zero so
1 Jan 1900 is
1900-1-1
It is possible to workaround that and include leading zeros but the expression gets much more complex.
Re: Source Template Definition and Generic Type
Posted: 29 Mar 2023 16:12
by Gary_G
Thank you, "tatewise";
First; I don't want to hijack this thread. So; I will start another of this more specific topic and copy the following, if you feel this would be better.
I'm trying to auto-generate a source title that matches my existing filing scheme based upon the contents of what I enter into the fields of a fully "splitter"-style (citation portion only) template.
Genealogy__Bazin_(Calixte_Donatien)__FE__MARR_1829-10-24__001__1-2
As this is a standard format for me, I will need to use your second approach, in order to be independent of the preferred date settings.
I've managed to determine how to generate all elements save two; the GEDCOM tag, used to identify the record-type, and the sortable date string.
As you can see, I do actually need to have leading zeros in the date elements. So; any additional suggestions to achieve that goal would be helpful.
I think, based on other posts, I should be able to translate "born|married|died|buried" into the related GEDCOM standard tags that I use as an abbreviation.
As I'm not yet familiar with the underpinnings of FH7, but I note that it looks like it uses a relational database. So; I wonder if it has the concept of stored procedures etc., which would allow one to store a complex function for creating the YYYY-MM-DD element. This is because it is so widely used in sorting dates and you say it would be much more complex that what you posted.
Re: Source Template Definition
Posted: 29 Mar 2023 16:54
by tatewise
I've created this new thread for you Gary.
Re: Source Template Definition
Posted: 29 Mar 2023 16:57
by Gary_G
Thank you, "tatewise".
Sometimes a simple question becomes more complex than expected and needs its own thread.
Re: Source Template Definition
Posted: 29 Mar 2023 17:11
by tatewise
FH does not use a relational database. FH has its own custom data structures (which is why it is so fast) and they are based closely on the GEDCOM data structures. It cannot save processes.
The thread
Date format in queries (19020) posed the same problem with this expression as a solution:
=Text(TextIf(%FACT.DATE:DAY% <= 9,Text("0" . Text(%FACT.DATE:DAY%)),Text(%FACT.DATE:DAY%)) . "/" . TextIf(%FACT.DATE:MONTH_NUMBER% <= 9,Text("0" . Text(%FACT.DATE:MONTH_NUMBER%)),Text(%FACT.DATE:MONTH_NUMBER%)) . "/" . Text(%FACT.DATE:YEAR%))
You need to replace
"/" with
"-" and
FACT.DATE with
SOUR.~DT-DATE and change the order to produce yyyy-mm-dd.
I'll check to see if it can be further simplified.
Re: Source Template Definition
Posted: 29 Mar 2023 17:21
by Gary_G
Thank you, so much, "tatewise!
I had searched and couldn't find anything, but then I don't know my way around the board as you do.
This is such a key code snippet and I will be using it as part of all my templates source names.
I'll be following this thread in case you do find a more elegant method. Since this is to be used in autogenerated source name, I should be able to easily update the template with any further improvement.
I should also note that as a "visual learner", I really find actually seeing such code snippets to incredibly instructive. I can see what is being done and consult the reference material to see why they work. Hopefully; as I see more of them, my questions will be fewer. :>)
Re: Source Template Definition
Posted: 29 Mar 2023 17:34
by tatewise
I think this is a simpler expression and rearranged for your yyyy-mm-dd in a Source Template Definition format:
<{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%}>
The surrounding < angle brackets > are necessary to inhibit space characters between each { bracketed } component.
Otherwise, I suspect you can work out the rest.
Re: Source Template Definition
Posted: 29 Mar 2023 18:03
by Gary_G
Thank you, "tatewise".
Yes; I can figure out the rest. I wondered about that approach, but wasn't quite sure how to implement it.
Re: Source Template Definition
Posted: 29 Mar 2023 18:43
by Medows
Mike/Gary...I am also learning from this because I also need the yyyy-mm-dd format.
Thanks, Alan
Re: Source Template Definition
Posted: 29 Mar 2023 21:43
by sbell95
I raised this recently in a pre-existing thread which may be of interest:
Re: Including update date in reports