Page 1 of 1

Formatting date point to include time

Posted: 14 Jun 2015 05:58
by shoshk
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

Re: Formatting date point to include time

Posted: 14 Jun 2015 09:27
by tatewise
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)

Re: Formatting date point to include time

Posted: 14 Jun 2015 14:33
by shoshk
Mike,

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

Shosh