*Date troubles.

Writing and using plugins for Version 5 and above.
User avatar
Ron Melby
Superstar
Posts: 348
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Date troubles.

Postby Ron Melby » 30 Jun 2019 14:54

Date = fhGetItemText(ptrFAM, '~.MARR.DATE:COMPACT')

I have searched, and perhaps I am missing it, misreading the doc available on this, but:

Date = fhGetItemText(ptrFAM, '~.MARR.DATE:YYYMMDD') doesn't appear to be available, in F,H on a computer, which is how underlyiing dates are usually stored to make for ordinal sort.

is there one or do I have to cut string and reverse, using the ABBREV3 or XDATE (dont remember which, I can look that up, the 12/12/1932 format?
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16051
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Date troubles.

Postby tatewise » 30 Jun 2019 16:09

A significant problem with dates is that they may not not be just one day, and may be a year or a year & month.
Also Period and Range dates such as from 1914 to 1918 and between 1914 and 1918 are more complex.
How do you want to handle all those?

Use strDate = fhGetItemText(ptrIndi,'~.BIRT.DATE:ABBREV3') that uses the definition in Tools > Preferences > General tab Preferred Short Date Format that offers several in yyyy mm dd order.
But Period and Range dates will produce such as 1914-1918
Unfortunately, those formats omit leading zeros, e.g. 1900/8/1 is 1-Aug-1900 so don't sort correctly :(
So some gsub() conversions will need to insert those missing zeros.

An alternative is to use datDate = fhGetValueAsDate( fhGetItemPtr(ptrIndi,'~.BIRT.DATE') )
Then use it to buddy sort the text date.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
Ron Melby
Superstar
Posts: 348
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Date troubles.

Postby Ron Melby » 30 Jun 2019 17:13

ok, thats sort of what I had gleaned out of it. ABBREV3 and cut and reverse it, installing leading zeros as needed,
FH V.6.2.7 Win 7 64 bit

User avatar
tatewise
Megastar
Posts: 16051
Joined: 25 May 2010 11:00
Family Historian: V6.2
Location: Torbay, Devon, UK
Contact:

Re: Date troubles.

Postby tatewise » 30 Jun 2019 20:17

You don't have to cut and reverse if you set Preferred Short Date Format as I suggested to say yyyy/mm/dd.
BUT also note what I said about Period and Range dates.

Anyway you don't have to cut & reverse as it can all be done with gsub().
If the format is dd/mm/yyyy then use:
Date = Date:gsub("^(%d+)/(%d+)/(%d+)$","%3/%2/%1")
and then use the Date:gsub() below to insert leading zeros.

Another option is shown below but will return nothing for most Period and Range dates:
local Year = fhGetItemText(ptrIndi,'~.BIRT.DATE:YEAR')
local Month = fhGetItemText(ptrIndi,'~.BIRT.DATE:MONTH_NUMBER')
local Day = fhGetItemText(ptrIndi,'~.BIRT.DATE:DAY')
local Date = Year.."/"..Month.."/"..Day
Date = Date:gsub("/(%d)/","/0%1/")
Date = Date:gsub("/(%d)$","/0%1")

OR as I said use a Buddy sort which works for ALL types of date.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry


Return to “Plugin Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest