* Date troubles.

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Ron Melby
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Date troubles.

Post by Ron Melby »

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 10 64 bit
User avatar
tatewise
Megastar
Posts: 28434
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Date troubles.

Post by tatewise »

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
Megastar
Posts: 928
Joined: 15 Nov 2016 15:40
Family Historian: V6.2

Re: Date troubles.

Post by Ron Melby »

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 10 64 bit
User avatar
tatewise
Megastar
Posts: 28434
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Date troubles.

Post by tatewise »

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
Post Reply