* Get Year from event when contains BEF, AFT etc

Writing and using plugins for Version 5 and above.
Post Reply
avatar
quarlton
Famous
Posts: 138
Joined: 26 Feb 2004 13:07
Family Historian: V7
Location: Lincolnshire
Contact:

Get Year from event when contains BEF, AFT etc

Post by quarlton » 27 Jun 2022 16:46

Hi

I'm trying to get a person's year of birth.
My first attempt works as long as the date just contains a number, but fails (understandably) if it contains Bef or Aft etc.

pi - pointer to an INDI record

What I want get is Year part of their BIRT date

This works fine as long as YEAR is just a number
iYear = tonumber(fhGetItemText(pi,'~.BIRT.DATE:YEAR'))

However it fails if YEAR contains Before, After etc.

Was going to try

iYear = fhCallBuiltInFunction(%INDI.BIRT[1].DATE:YEAR%)

but couldn't work out how to pass the pointer pi to represent the INDI

Suggestions gratefully received
Dave Simpson ~ Boulton, Braham, Carney, Simpson and Jacobs

User avatar
tatewise
Megastar
Posts: 24622
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Get Year from event when contains BEF, AFT etc

Post by tatewise » 27 Jun 2022 17:58

Dave, the fact is that Date values are potentially a complex data structure and need careful handling.

Qualifiers like :YEAR only work for simple Date formats.
See the Help for General Topics > Date Formats that illustrates how qualifiers behave.

In the case of Before and After, etc, check the Date Entry Assistant and you will find they are Range (or Period) Dates.
Such dates have two date points.

To cater for all forms of Date you should review the Plugin Help for Objects + Date and Datept.
Simple dates only have one Datept but Range/Period Dates have two Datept values.
Start with:
ptrDate = fhGetItemPtr( pi, "~.BIRT.DATE" )
datDate = fhGetValueAsDate( ptrDate )

dpDatePt1 = datDate:GetDatePt1()
iYear1 = dpDatePt1:GetYear()

dpDatePt2 = datDate:GetDatePt2()
iYear2 = dpDatePt2:GetYear()

Exactly what you do depends on your objectives...
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
quarlton
Famous
Posts: 138
Joined: 26 Feb 2004 13:07
Family Historian: V7
Location: Lincolnshire
Contact:

Re: Get Year from event when contains BEF, AFT etc

Post by quarlton » 27 Jun 2022 21:35

Hi Mike


Many thanks, that works (obviously).

I will need to do the reading as you suggest to work out just what is going on.

Dave
Dave Simpson ~ Boulton, Braham, Carney, Simpson and Jacobs

Post Reply