Page 1 of 1

Get Year from event when contains BEF, AFT etc

Posted: 27 Jun 2022 16:46
by quarlton
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

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

Posted: 27 Jun 2022 17:58
by tatewise
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...

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

Posted: 27 Jun 2022 21:35
by quarlton
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