* Formatting date point to include time

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
avatar
shoshk
Famous
Posts: 242
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Formatting date point to include time

Post by shoshk » 14 Jun 2015 05:58

Hi,

I've looked for this in the help but just can't find it...

I'm trying to format the result from LastUpdated (a datepoint) to include the time. I then store this information in my external DB.

I tried using:

dpLastUpdated = fhCallBuiltInFunction('LastUpdated', pi)
LastUpdated = string.format('%d %b %y %H:%S', dpLastUpdated)

But that doesn't work. I got the message: bad argument #2 to 'format' (number expected, got userdata). So I guess string.format doesn't understand datepoints.

I appreciate your help with this.

Shosh
Shosh Kalson

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

Re: Formatting date point to include time

Post by tatewise » 14 Jun 2015 09:27

Hi Shosh.
There are a few new features in FH V6 that have not been documented, and this is one of them.
Calico Pie have been informed, but probably have more important matters to sort out.
In this case the details are:

Understanding Functions > LastUpdated

Now returns Date + Time but is undocumented.
Date parts can be extracted using Date(LastUpdated(%INDI%)) or Year(LastUpdated(%INDI%)), etc, but how is Time extracted?

If used in Plugins via fhCallBuiltInFunction it returns three parameters:
DatePoint, IntegerHour, IntegerMinute = fhCallBuiltInFunction("LastUpdated",ptrRec)

You are correct that string.format() does not understand the FH internal DatePoint format.
The FH Plugin Help > The FH API > Objects > Datept section explains the available methods.
In this case use:
IntegerDay = DatePoint:GetDay()
IntegerMonth = DatePoint:GetMonth()
IntegerYear = DatePoint:GetYear()

then with a 'C' printf style format string:

LastUpdated = string.format("%02d %02d %04d %02d:%02d", IntegerDay,IntegerMonth,IntegerYear,IntegerHour,IntegerMinute)
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
shoshk
Famous
Posts: 242
Joined: 13 May 2015 16:28
Family Historian: V7
Location: Mitzpe Jericho, Israel

Re: Formatting date point to include time

Post by shoshk » 14 Jun 2015 14:33

Mike,

Thank you. That's exactly what I was looking for. Glad to know it was added to FH.

Shosh
Shosh Kalson

Post Reply